强烈向大家推荐一个好网站,【我要自学网】,教程由在校老师录制,有办公会计、平面设计、室内设计、机械设计、网页编程、影视动画等教程.....让你足不出门,都可以体验学校的专业教育!
很多站长在部署了https后,默认访问的网站仍然是http,需要手动去访问https才行。
今天小白在这个告诉大家一个简单的代码,在nginx站点配置中加一段简单的判断跳转就可以实现,不需要使用伪静态跳转。
在nginx的站点配置中加上一段
if ($server_port !~ 443){
rewrite ^/.*$ https://$host$uri;
}
在配置文件中
server
{
listen 80;
listen 443 ssl;
server_name 123.123.123.123 123.56.161.140;
index index.php index.html index.htm default.php default.htm default.html;
root /www/wwwroot/123.56.161.140;
#error_page 404/404.html;
ssl_certificate key/123.56.161.140/key.csr;
ssl_certificate_key key/123.56.161.140/key.key;
if ($server_port !~ 443){
rewrite ^/.*$ https://$host$uri;
}
error_page 497 https://$host$uri;
error_page 404 /404.html;
error_page 502 /502.html;
include enable-php-71.conf;
include rewrite/123.56.161.140.conf;
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
access_log off;
}
location ~ .*\.(js|css)?$
{
expires 12h;
access_log off;
}
access_log /www/wwwlogs/123.56.161.140.log;
}
这样就可以判断当访问不是80端口,自动加上https。
流觞



