These are examples of the Nginx configurations I have fine tuned over the past few months. These are specifically for passing connections to Apache.
Nginx = Frontend
Apache = Backend
SSL Config:
(Will redirect to SSL)
[php]
server {
listen 80;
server_name domain.org;
server_name www.domain.org;
return 301 https://$server_name$request_uri;
server_tokens off;
access_log off;
error_log off;
}
server {
listen 443;
root /path/to/public_html;
index index.php index.html index.htm;
ssl on;
ssl_certificate /etc/nginx/ssl/site/certificate.crt;
ssl_certificate_key /etc/nginx/ssl/site/private.key;
ssl_dhparam /etc/nginx/ssl/site/dhparam.pem;
ssl_stapling on;
ssl_stapling_verify on;
ssl_trusted_certificate /etc/nginx/ssl/site/certificate.crt;
resolver 213.73.91.35 77.109.138.45 77.109.139.29 valid=300s;
resolver_timeout 10s;
ssl_session_timeout 5m;
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128:AES256:AES:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:50m;
add_header Strict-Transport-Security max-age=15768000;
add_header X-Frame-Options SAMEORIGIN;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
server_name domain.org;
server_name www.domain.org;
server_tokens off;
access_log off;
error_log off;
location / {
proxy_pass https://IP_Address_Here:443;
proxy_redirect off;
proxy_buffering off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
}
}
[/php]
Non SSL Config:
(Uses port 80)
[php]
server {
listen 80;
server_name domain.org;
server_name www.domain.org;
root /path/to/public_html;
index index.php index.html index.htm;
# Parameters #
server_tokens off;
access_log off;
error_log off;
# Security #
add_header X-Frame-Options SAMEORIGIN;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
location / {
proxy_pass http://IP_Address_Here:80;
proxy_buffering off;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
}
}
[/php]