nginx设置http定向https
2023-10-12 17:58:22浏览:67windows服务器,没有安装宝塔面板,相关服务还是手动一步一步设置,以下是设置http根域名访问时,强制为https的www二级域名下,同样https根域名访问,也强制到https的www二级域名下。
server { listen 443 ssl; server_name youname.com www.youname.com; if ($host ~ '^youname.com'){ return 301 https://www.youname.com$request_uri; } ssl_certificate C:\......证书路径........\ssl\Nginx\fullchain.pem; ssl_certificate_key C:\....证书路径.........\ssl\Nginx\privkey.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; location / { root C:\case; index index.php index.html index.htm; } include url.conf; location ~ \.php$ { root C:\case; fastcgi_pass 127.0.0.1:9000; index index.php index.html index.htm; #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } server { listen 80; server_name youname.com www.youname.com; if ($host ~ '^youname.com'){ return 301 https://www.youname.com$request_uri; } rewrite ^(.*)$ https://$host$1 permanent; location / { root C:\Dev\case\jinglongyuan; index index.php index.html index.htm; } include url.conf; location ~ \.php$ { root C:\case; fastcgi_pass 127.0.0.1:9000; index index.php index.html index.htm; #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }