nginx Http跳转到Https

给网站配置https证书

nginx配置文件监听80和443,

当访问80端口的时候自动跳转到443

```
server {
listen 443;
ssl on;
ssl_certificate www.test.cn.crt; #证书
ssl_certificate_key www.test.cn.key; #私钥
server_name www.test.cn;
root "/var/www/html/test/public";
access_log /usr/local/nginx/logs/www.test.com.log main;
error_log /usr/local/nginx/logs/www.test.com.error.log;
location / {
index index.html index.htm index.php;
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
}
}
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
location ^~ /v/{
proxy_pass http://10.10.0.6:8096/;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)?$ {
expires 1d;
access_log off;
}
}
server {
listen 80;
server_name www.test.cn;
root "/var/www/html/test/public";
rewrite ^(.*)$ https://$host$1 permanent;
}
```

    A+
发布日期:2020年10月14日  所属分类:未分类

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: