本文最后更新于:几秒前
以下是一个静态文件代理的示例配置,启用了SSL:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| server { listen 443 ssl; server_name example.com;
ssl_certificate /path/to/your/certificate.crt; ssl_certificate_key /path/to/your/private.key; ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers HIGH:!aNULL:!MD5;
root /path/to/your/static/files;
location /static/ { alias /path/to/your/static/files/; expires 30d; access_log /var/log/nginx/static_access.log; }
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ { root /path/to/your/static/files; expires 7d; access_log off; } }
server { listen 80; server_name example.com; return 301 https://$server_name$request_uri; }
|
配置解析
listen 443 ssl
:开启443端口的SSL监听,启用HTTPS。
ssl_certificate
和 ssl_certificate_key
:指定SSL证书文件和私钥文件的路径。
ssl_protocols
和 ssl_ciphers
:设置SSL协议版本和加密套件,以确保安全性。
return 301 https://$server_name$request_uri;
:将HTTP请求自动重定向到HTTPS,保证所有访问都通过加密连接。
这样配置后,访问静态资源时会通过HTTPS加密传输,提升了数据的安全性。