|
| 1 | +# run nginx in foreground |
| 2 | +daemon off; |
| 3 | +error_log /DATA/logs/nginx/error.log warn; |
| 4 | +pid /var/run/nginx.pid; |
| 5 | +env DB_HOST; |
| 6 | +env DB_NAME; |
| 7 | +env DB_USER; |
| 8 | +env DB_PASS; |
| 9 | +worker_processes auto; |
| 10 | +events { |
| 11 | + worker_connections 4096; |
| 12 | +} |
| 13 | +http { |
| 14 | + sendfile on; |
| 15 | + include /etc/nginx/mime.types; |
| 16 | + include /etc/nginx/fastcgi.conf; |
| 17 | + default_type application/octet-stream; |
| 18 | + tcp_nopush on; |
| 19 | + client_body_temp_path /tmp/nginx/body 1 2; |
| 20 | + client_max_body_size 0; |
| 21 | + fastcgi_temp_path /tmp/nginx/fastcgi_temp 1 2; |
| 22 | + #a new log format for detecting bad bots. |
| 23 | + log_format blocked '$time_local: Blocked request from $http_x_real_ip $request'; |
| 24 | + ## This log format makes it so we can see real requester's IP address \ |
| 25 | + ## not just the reverse proxy server's IP address. Also note, that \ |
| 26 | + ## "specialLog" can be replaced with any name you would like to \ |
| 27 | + ## give to this log format. |
| 28 | + log_format specialLog '$http_x_real_ip - $remote_user [$time_local] ' |
| 29 | + '"$request" $status $body_bytes_sent ' |
| 30 | + '"$http_referer" "$http_user_agent"'; |
| 31 | + # client_max_body_size 2G; |
| 32 | + server { |
| 33 | + #listen [::]:80; #uncomment for IPv6 support |
| 34 | + listen 80; |
| 35 | + root /DATA/htdocs/current; |
| 36 | + index index.php index.html index.htm; |
| 37 | + access_log /DATA/logs/nginx/access.log specialLog; |
| 38 | + error_log /DATA/logs/nginx/error.log; |
| 39 | + disable_symlinks off; |
| 40 | + location = /robots.txt { |
| 41 | + allow all; |
| 42 | + log_not_found off; |
| 43 | + access_log off; |
| 44 | + } |
| 45 | + # deny dot-files |
| 46 | + location ~ /\. { |
| 47 | + deny all; |
| 48 | + access_log off; |
| 49 | + log_not_found off; |
| 50 | + } |
| 51 | + #Yoast SEO Sitemaps |
| 52 | + location ~ ([^/]*)sitemap(.*).x(m|s)l$ { |
| 53 | + ## this redirects sitemap.xml to /sitemap_index.xml |
| 54 | + rewrite ^/sitemap.xml$ /sitemap_index.xml permanent; |
| 55 | + ## this makes the XML sitemaps work |
| 56 | + rewrite ^/([a-z]+)?-?sitemap.xsl$ /index.php?xsl=$1 last; |
| 57 | + rewrite ^/sitemap_index.xml$ /index.php?sitemap=1 last; |
| 58 | + rewrite ^/([^/]+?)-sitemap([0-9]+)?.xml$ /index.php?sitemap=$1&sitemap_n=$2 last; |
| 59 | + ## The following lines are optional for the premium extensions |
| 60 | + ## News SEO |
| 61 | + rewrite ^/news-sitemap.xml$ /index.php?sitemap=wpseo_news last; |
| 62 | + ## Local SEO |
| 63 | + rewrite ^/locations.kml$ /index.php?sitemap=wpseo_local_kml last; |
| 64 | + rewrite ^/geo-sitemap.xml$ /index.php?sitemap=wpseo_local last; |
| 65 | + ## Video SEO |
| 66 | + rewrite ^/video-sitemap.xsl$ /index.php?xsl=video last; |
| 67 | + } |
| 68 | + location / { |
| 69 | + try_files $uri $uri/ /index.php?$args; |
| 70 | + } |
| 71 | + # Deny access to any files with a .php extension in the uploads directory |
| 72 | + # Works in sub-directory installs and also in multisite network |
| 73 | + # Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban) |
| 74 | + location ~* /(?:uploads|files)/.*\.php$ { |
| 75 | + deny all; |
| 76 | + } |
| 77 | + ## Disable .htaccess and other hidden files |
| 78 | + location ~ /\. { |
| 79 | + deny all; |
| 80 | + access_log off; |
| 81 | + log_not_found off; |
| 82 | + } |
| 83 | + location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ { |
| 84 | + access_log off; |
| 85 | + log_not_found off; |
| 86 | + expires 360d; |
| 87 | + } |
| 88 | + # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 |
| 89 | + location ~ [^/]\.php(/|$) { |
| 90 | + fastcgi_split_path_info ^(.+?\.php)(/.*)$; |
| 91 | + if (!-f $document_root$fastcgi_script_name) { |
| 92 | + return 404; |
| 93 | + } |
| 94 | + fastcgi_pass 127.0.0.1:9000; |
| 95 | + fastcgi_index index.php; |
| 96 | + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; |
| 97 | + include fastcgi_params; |
| 98 | + fastcgi_buffers 16 16k; |
| 99 | + fastcgi_buffer_size 32k; |
| 100 | + } |
| 101 | + ## Block SQL injections |
| 102 | + location ~* union.*select.*\( { access_log /DATA/logs/nginx/blocked.log blocked; deny all; } |
| 103 | + location ~* union.*all.*select.* { access_log /DATA/logs/nginx/blocked.log blocked; deny all; } |
| 104 | + location ~* concat.*\( { access_log /DATA/logs/nginx/blocked.log blocked; deny all; } |
| 105 | + ## Block common exploits |
| 106 | + location ~* (<|%3C).*script.*(>|%3E) { access_log /DATA/logs/nginx/blocked.log blocked; deny all; } |
| 107 | + location ~* base64_(en|de)code\(.*\) { access_log /DATA/logs/nginx/blocked.log blocked; deny all; } |
| 108 | + location ~* (%24&x) { access_log /DATA/logs/nginx/blocked.log blocked; deny all; } |
| 109 | + location ~* (%0|%A|%B|%C|%D|%E|%F|127\.0) { access_log /DATA/logs/nginx/blocked.log blocked; deny all; } |
| 110 | + location ~* \.\.\/ { access_log /DATA/logs/nginx/blocked.log blocked; deny all; } |
| 111 | + location ~* ~$ { access_log /DATA/logs/nginx/blocked.log blocked; deny all; } |
| 112 | + location ~* proc/self/environ { access_log /DATA/logs/nginx/blocked.log blocked; deny all; } |
| 113 | + location ~* /\.(htaccess|htpasswd|svn) { access_log /DATA/logs/nginx/blocked.log blocked; deny all; } |
| 114 | + ## Block file injections |
| 115 | + location ~* [a-zA-Z0-9_]=(\.\.//?)+ { access_log /DATA/logs/nginx/blocked.log blocked; deny all; } |
| 116 | + location ~* [a-zA-Z0-9_]=/([a-z0-9_.]//?)+ { access_log /DATA/logs/nginx/blocked.log blocked; deny all; } |
| 117 | + ## wordpress security |
| 118 | + location ~* wp-config.php { access_log /DATA/logs/nginx/blocked.log blocked; deny all; } |
| 119 | + location ~* wp-admin/includes { access_log /DATA/logs/nginx/blocked.log blocked; deny all; } |
| 120 | + location ~* wp-app\.log { access_log /DATA/logs/nginx/blocked.log blocked; deny all; } |
| 121 | + location ~* (licence|readme|license)\.(html|txt) { access_log /DATA/logs/nginx/blocked.log blocked; deny all; } |
| 122 | + location ~* xmlrpc.php { access_log /DATA/logs/nginx/blocked.log blocked; deny all; } |
| 123 | + # location ~ ^(wp-admin|wp-login.php) { |
| 124 | + # try_files $uri $uri/ /index.php?$args; |
| 125 | + # index index.html index.htm index.php; |
| 126 | + # allow 91.105.68.253; # First IP to allow access |
| 127 | + # allow x.x.x.x; # Second IP to allow access |
| 128 | + # allow x.x.x.x; # Third IP to allow access |
| 129 | + # deny all; |
| 130 | + # error_page 403 = @wp_admin_ban; |
| 131 | + # } |
| 132 | + location @wp_admin_ban { |
| 133 | + rewrite ^(.*) http://localhost permanent; |
| 134 | + } |
| 135 | + gzip on; |
| 136 | + gzip_disable "msie6"; |
| 137 | + gzip_vary on; |
| 138 | + gzip_proxied any; |
| 139 | + gzip_comp_level 6; |
| 140 | + gzip_buffers 16 8k; |
| 141 | + gzip_http_version 1.1; |
| 142 | + gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; |
| 143 | + } |
| 144 | +} |
0 commit comments