LNMP1.4开启https疑问
配置好https后,http和https两个都可以正常访问。如何让所有访问都是https?有301重定向的
server {
listen 443 ssl;
server_name file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\`7_{~]GF$3{MOQ4V_}PH]YC.pngxxxxxx.com;
省略其他配置
}
server {
listen 80;
server_name file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\`7_{~]GF$3{MOQ4V_}PH]YC.pngwww.xxxxxx.com;
return 301 file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\%W@GJ$ACOF(TYDYECOKVDYB.pnghttps://xxxxxx.com$request_uri;
}
还有我使用的一个面板它自动配置的,我看了下配置文件是这样的:
server
{
listen 80;
listen 443 ssl;
server_name file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\`7_{~]GF$3{MOQ4V_}PH]YC.pngxxxxxx.com;
index index.php index.html index.htm default.php default.htm default.html;
root /www/wwwroot/file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\`7_{~]GF$3{MOQ4V_}PH]YC.pngxxxxxx.com;
#error_page 404/404.html;
ssl_certificate /etc/letsencrypt/live/file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\%W@GJ$ACOF(TYDYECOKVDYB.pngxxxxxx.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\%W@GJ$ACOF(TYDYECOKVDYB.pngxxxxxx.com/privkey.pem;
if ($server_port !~ 443){
rewrite ^/.*$ file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\%W@GJ$ACOF(TYDYECOKVDYB.pnghttps://$host$request_uri permanent;
}
省略一堆......
就是
if ($server_port !~ 443){
rewrite ^/.*$ file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\%W@GJ$ACOF(TYDYECOKVDYB.pnghttps://$host$request_uri permanent;
}
我网上查下了下还有直接
rewrite ^(.*)$ file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\%W@GJ$ACOF(TYDYECOKVDYB.pnghttps://$host$1 permanent;
都有什么区别..... 官网上都写了教程的
添加ssl参考:https://lnmp.org/faq/lnmp-vhost-add-howto.html
http跳转到https 参考:https://lnmp.org/faq/lnmp-nginx-301-rewrite.html
回复 2# 的帖子
会配置https,就是问下rewrite ^(.*)$https://$host$1 permanent;这样和301有什么区别?
页:
[1]