Nginx SSL Config
openssl dhparam -out dhparam.pem 2048 # 如果你的机器性能足够强大,可以用 4096 位加密
server {
listen 443 ssl http2;
server_name www.example.com;
#ssl on;
ssl_certificate /etc/ssl/certs/ssl-bundle.crt;#证书文件
ssl_certificate_key /etc/ssl/private/www_example_com.key;#私钥
ssl_dhparam /etc/ssl/certs/dhparam.pem;#刚刚生成的那个pem文件的路径
ssl_session_cache shared:SSL:10m;#开启缓存,有利于减少ssl握手开销
ssl_session_timeout 10m;#SSL会话过期时间,有利于减少服务器开销
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;#指定可用的ssl协议,排除sslV3等容易被攻击的协议
ssl_stapling on;#开启证书吊销状态检查
ssl_trusted_certificate /etc/ssl/certs/ssl-bundle.crt;#这个证书路径跟上面一样
ssl_ciphers "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384: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:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA";#屏蔽不安全的加密方式
ssl_prefer_server_ciphers on;
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";#开启HSTS,强制全站加密,如果你的网站要引用不加密的资源,或者考虑将来取消加密,就不要开这个
location / {
……………………
}
}
同时,如果是全站 HTTPS 并且不考虑 HTTP 的话,可以加入 HSTS 告诉你的浏览器本网站全站加密,并且强制用 HTTPS 访问
add_header Strict-Transport-Security max-age=63072000;
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
或者在 Nginx 中配置将 HTTP 请求全部重定向到 HTTPS
server {
listen 80;
server_name example.com;
return 301 https://example.com$request_uri;
}
nginx websocks反代
location / {
proxy_pass http://example.com:8080; # 转发规则
proxy_set_header Host $proxy_host; # 修改转发请求头,让8080端口的应用可以受到真实的请求
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;