nginx配置http访问自动跳转到https
一般我们的nignx配置ssl的时候
server {
listen 80;
listen 443 ssl;
ssl_certificate /www/ssl/2097158_wx.wanjiejixie.com.pem;
ssl_certificate_key /www/ssl/2097158_wx.wanjiejixie.com.key;
root /www/web/wx/public_html;
server_name wx.wanjiejixie.com;
index index.html index.php index.htm;
error_page 400 /errpage/400.html;
error_page 403 /errpage/403.html;
error_page 404 /errpage/404.html;
error_page 503 /errpage/503.html;
location ~ \.php$ {
proxy_pass http://127.0.0.1:88;
include naproxy.conf;
}
location ~ /\.ht {
deny all;
}
location / {
try_files $uri @apache;
}
location @apache {
proxy_pass http://127.0.0.1:88;
include naproxy.conf;
}
}
我的ssl证书是这样配置的 但是这种 http的还是可以访问 没有默认到https的站点
那么我们把 两个配置分开
server {
listen 80;
server_name wx.wanjiejixie.com;
rewrite ^(.*) https://$server_name$1 permanent;
}
server {
listen 443 ssl;
ssl_certificate /www/ssl/2097158_wx.wanjiejixie.com.pem;
ssl_certificate_key /www/ssl/2097158_wx.wanjiejixie.com.key;
root /www/web/wx/public_html;
server_name wx.wanjiejixie.com;
index index.html index.php index.htm;
error_page 400 /errpage/400.html;
error_page 403 /errpage/403.html;
error_page 404 /errpage/404.html;
error_page 503 /errpage/503.html;
location ~ \.php$ {
proxy_pass http://127.0.0.1:88;
include naproxy.conf;
}
location ~ /\.ht {
deny all;
}
location / {
try_files $uri @apache;
}
location @apache {
proxy_pass http://127.0.0.1:88;
include naproxy.conf;
}
}
当遇到http访问的时候自动跳转到https的站点 配置完成后 重启nignx