To create one host nginx for static site:
server {
listen 80;
server_name www.yourhost.com yourhost.com;
root /home/www/yourhost/;
location ~ {
try_files $uri $uri/ /index.html =404;
}
}
server {
listen 80;
server_name www.yourhost.com yourhost.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name www.yourhost.com yourhost.com;
ssl on;
ssl_certificate /path/to/your/ssl/certificate;
ssl_certifiate_key /path/to/your/ssl/cert_key;
root /home/www/yourhost/;
location ~ {
try_files $uri $uri/ /index.html =404;
}
}
Replace yourhost.com
to your domain, /path/to/your/ssl/certificate
and /cert_key
to path to your certificate and key,
replace /home/www/yourhost/
to path to dir with your static.
Example:
server {
listen 80;
server_name www.yourhost.com yourhost.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name www.yourhost.com yourhost.com;
resolver 127.0.0.1;
ssl on;
ssl_stapling on;
ssl_certificate /path/to/your/ssl/certificate;
ssl_certifiate_key /path/to/your/ssl/cert_key;
ssl_session_timeout 24h;
ssl_session_cache shared:SSL:2m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:ECDHE-RSA-AES128-GCM-SHA256:AES256+EECDH:DHE-RSA-AES128-GCM-SHA256:AES256+EDH:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4";
ssl_prefer_server_ciphers on;
ssl_dhparam /etc/ssl/certs/dhparam.pem;
add_header Strict-Transport-Security "max-age=31536000;";
add_header Content-Security-Policy-Report-Only "default-src https:; script-src https: 'unsafe-eval' 'unsafe-inline'; style-src https: 'unsafe-inline'; img-src https: data:; font-src https: data:; report-uri /csp-report";
root /home/www/yourhost/;
location ~ {
try_files $uri $uri/ /index.html =404;
}
}
Before save your config, you need to generate dhparam