SSL安全证书

Nginx 自动跳转到HTTPS

适用于 80端口和443 配置在同一个 server{}内

  1. if ($server_port = 80) {
  2. rewrite ^(.*)$ https://$host$1 permanent;
  3. }

配置示例:

  1. server {
  2. listen 80;
  3. server_name www.22.cn;
  4. rewrite ^ https://$http_host$request_uri? permanent;
  5. }
  6. server {
  7. listen 443;
  8. ssl on;
  9. ssl_certificate /etc/ssl/cacert.pem;
  10. ssl_certificate_key /etc/ssl/privkey.pem;
  11. server_name www.22.cn;
  12. server_tokens off;
  13. location / {
  14. fastcgi_param HTTPS on;
  15. fastcgi_param HTTP_SCHEME https;
  16. }
  17. }