Guest User

Untitled

a guest
Jun 5th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Nginx 8.09 KB | None | 0 0
  1. server {
  2.     # defines on which port the Server listens
  3.     listen 443 ssl;
  4.    
  5.     # Necessary to see the externalincoming IP
  6.     # DO NOT USE THIS WHEN ON BARE METAL! ONLY ON MY DOCKER INFRASTRUCTRE!
  7.     real_ip_header X-Forwarded-For;
  8.     set_real_ip_from "x.x.x.x/16";
  9.    
  10.     # only allow secure protocols
  11.     ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  12.  
  13.     # custom DH
  14.     # TODO
  15.     # YOU NEED TO CREATE THESE WITH:
  16.     # openssl dhparam -outform PEM -out dhparam2048.pem 2048
  17.     ssl_dhparam /path/to/dhparam2048.pem;
  18.     # choose eleptic curve with 384 bit
  19.     # equal to 7680 bit RSA
  20.     ssl_ecdh_curve secp384r1;
  21.    
  22.     # set prefer ciphers
  23.     ssl_prefer_server_ciphers on;
  24.  
  25.     # define which ciphers to allow
  26.     ssl_ciphers "EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 EECDH+aRSA+RC4 EECDH EDH+aRSA !RC4 !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS";
  27.    
  28.     # define where ssl certs are stored
  29.     ssl_certificate /etc/nginx/ssl/www.name-of-website.tld/nameof.crt;
  30.     ssl_certificate_key /etc/nginx/ssl/www.name-of-website.tld/nameof.key;
  31.    
  32.     # defines the fqdn(s) for this vhost
  33.     server_name www.name-of-website.tld;
  34.  
  35.     # Document root for this vhost
  36.     root /var/www/www.name-of-website.tld;
  37.  
  38.     # create separate log and error files for this vhost
  39.     access_log  /var/log/nginx/www.name-of-website.tld/access.log;
  40.     error_log   /var/log/nginx/www.name-of-website.tld/error.log;
  41.  
  42.     #define index file(s) for this vhost
  43.     index index.php index.html index.htm default.html default.htm;
  44.  
  45.     # Add headers to serve SECURITY related headers
  46.     add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;";
  47.     add_header X-Content-Type-Options nosniff;
  48.     add_header X-Frame-Options "SAMEORIGIN";
  49.     add_header X-XSS-Protection "1; mode=block";
  50.     add_header X-Robots-Tag none;
  51.     add_header X-Download-Options noopen;
  52.     add_header X-Permitted-Cross-Domain-Policies none;
  53.     # TODO
  54.     # !!! TO GET PUBLIC KEY PINNING WORKING YOU NEED TO INSERT THE VALUE HERE! !!!
  55.     # EXAMPLE:
  56.     # openssl x509 -in your-key-file.key -pubkey -noout | openssl rsa -pubin -outform der | openssl dgst -sha256 -binary | base64
  57.     ###
  58.     # YOU ALSO NEED TO APPLY A BACKUP_KEY FOR A CA! DOWNLOAD THIS CRT AND GET THE HASH FOR IT
  59.     # EXAMPLE:
  60.     # openssl x509 -in ca.crt -pubkey -noout | openssl rsa -pubin -outform der | openssl dgst -sha256 -binary | base64
  61.     add_header Public-Key-Pins 'pin-sha256="CURRENT-KEY-HASH"; pin-sha256="BACKUP-KEY-HASH" max-age=31536000; includeSubDomains';
  62.  
  63.  
  64.     # Disable gzip to avoid the removal of the ETag header
  65.     gzip off;
  66.  
  67.     # disable logging for robots.txt
  68.     location = /robots.txt {
  69.         allow all;
  70.         log_not_found off;
  71.         access_log off;
  72.     }
  73.  
  74.     # Support Clean (aka Search Engine Friendly) URLs
  75.     location / {
  76.         try_files $uri $uri/ /index.php?$args;
  77.  
  78.     }
  79.  
  80.     # Deny all attempts to access hidden files such as .htaccess, .htpasswd,
  81.     # .DS_Store (Mac).
  82.     location ~ /\. {
  83.         deny all;
  84.         access_log off;
  85.         log_not_found off;
  86.     }
  87.  
  88.     # enable php-fpm
  89.     location ~ \.php$ {
  90.         fastcgi_pass  127.0.0.1:9000;
  91.         fastcgi_index index.php;
  92.         include fastcgi_params;
  93.         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  94.     }
  95.  
  96.     # Adding the cache control header for js and css files
  97.     # Make sure it is BELOW the location ~ \.php(?:$|/) { block
  98.     location ~* \.(?:css|js)$ {
  99.         add_header Cache-Control "public, max-age=7200";
  100.         # Add headers to serve security related headers
  101.         add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;";
  102.         add_header X-Content-Type-Options nosniff;
  103.         add_header X-Frame-Options "SAMEORIGIN";
  104.         add_header X-XSS-Protection "1; mode=block";
  105.         add_header X-Robots-Tag none;
  106.         # Optional: Don't log access to assets
  107.         #access_log off;
  108.     }
  109.    
  110.     ### SECURITY AND HARDENING OPTIONS ###
  111.     # Turn of the Server Tokens (webserver information)
  112.     server_tokens off;
  113.    
  114.     # Block out any script trying to base64_encode data within the URL.
  115.     if ($query_string ~ "base64_encode[^(]*\([^)]*\)") {
  116.         set $rule_0 1;
  117.     }
  118.  
  119.     # Block out any script that includes a ********** tag in URL.
  120.     if ($query_string ~ "(<|%3C)([^s]*s)+cript.*(>|%3E)"){
  121.         set $rule_0 1;
  122.     }
  123.  
  124.     # Block out any script trying to set a PHP GLOBALS variable via URL.
  125.     if ($query_string ~ "GLOBALS(=|\[|\%[0-9A-Z]{0,2})"){
  126.         set $rule_0 1;
  127.     }
  128.  
  129.     # Block out any script trying to modify a _REQUEST variable via URL.
  130.     if ($query_string ~ "_REQUEST(=|\[|\%[0-9A-Z]{0,2})"){
  131.         set $rule_0 1;
  132.     }
  133.    
  134.     if ($rule_0 = "1"){
  135.         rewrite /.* /index.php ;
  136.     }
  137.    
  138.     # Begin - Joomla! core SEF Section.
  139.     set $http_authorization $http_authorization;
  140.    
  141.     if ($uri !~ "^/index\.php"){
  142.         set $rule_0 1$rule_0;
  143.     }
  144.     if ($uri ~* "/component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$"){
  145.         set $rule_0 2$rule_0;
  146.     }
  147.     if ($rule_0 = "21"){
  148.         rewrite /.* /index.php last;
  149.     }
  150.  
  151.     # deny running scripts inside writable directories
  152.     location ~* /(images|cache|media|logs|tmp)/.*\.(php|pl|py|jsp|asp|sh|cgi)$ {
  153.         return 403;
  154.     }
  155.  
  156.     # caching of files ( default joomla)
  157.     location ~* \.(ico|pdf|flv)$ {
  158.         expires 1y;
  159.     }
  160.     location ~* \.(js|css|png|jpg|jpeg|gif|swf|xml|txt)$ {
  161.         expires 14d;
  162.     }
  163.  
  164.     ## Start: Size Limits & Buffer Overflows ##
  165.     # The directive specifies the client request body buffer size. (default is 8k)
  166.     client_body_buffer_size  1K;
  167.  
  168.     # Directive sets the headerbuffer size for the request header from client.
  169.     # !!!May have to be adjusted!!!!
  170.     client_header_buffer_size 1k;
  171.  
  172.     # Directive assigns the maximum accepted body size of client request
  173.     # Throws error 413
  174.     # !!!! if too small for POST stuff then we have to increase!!!!!
  175.     client_max_body_size 1k;
  176.  
  177.     # Directive assigns the maximum number and size of buffers for large headers to read from client request
  178.     large_client_header_buffers 2 1k;
  179.     ## END: Size Limits & Buffer Overflows ##
  180.  
  181.     ## Start: Timeouts ##
  182.     # Directive sets the read timeout for the request body from client.
  183.     # The timeout is set only if a body is not get in one readstep.
  184.     # If after this time the client send nothing, nginx returns error “Request time out” (408).
  185.     # The default is 60.
  186.     client_body_timeout   10;
  187.  
  188.     # Directive assigns timeout with reading of the title of the request of client.
  189.     # The timeout is set only if a header is not get in one readstep.
  190.     # If after this time the client send nothing, nginx returns error “Request time out” (408).
  191.     client_header_timeout 10;
  192.  
  193.     # The first parameter assigns the timeout for keep-alive connections with the client.
  194.     # The server will close connections after this time.
  195.     # The optional second parameter assigns the time value in the header Keep-Alive: timeout=time of the response.
  196.     # This header can convince some browsers to close the connection, so that the server does not have to.
  197.     # Without this parameter, nginx does not send a Keep-Alive header (though this is not what makes a connection “keep-alive”).
  198.     keepalive_timeout     5 5;
  199.  
  200.     # Directive assigns response timeout to client.
  201.     # Timeout is established not on entire transfer of answer,
  202.     # but only between two operations of reading, if after this time client will take nothing,
  203.     # then nginx is shutting down the connection.
  204.     send_timeout          10;
  205.     ## End: Timeouts ##
  206.  
  207.     # Only allow these request methods
  208.     # Do not accept DELETE, SEARCH and other methods
  209.     if ($request_method !~ ^(GET|HEAD|POST)$ ) {
  210.         return 444;
  211.     }
  212.  
  213.     # Deny certain Referers
  214.     if ( $http_referer ~* (babes|forsale|girl|jewelry|love|nudit|organic|poker|porn|sex|teen) )
  215.     {
  216.         # return 404;
  217.         return 403;
  218.     }
  219.     }
Add Comment
Please, Sign In to add comment