有时我们需要给同一个域名配置http和https两种方式访问,例如微信小程序接口需要https请求。
我们可以在不改变原http请求的基础上,增加对https的支持。
一 编辑nginx配置文件,在server段添加ssl配置(证书可以在阿里云上免费申请)
1 server
2 {
3 listen 80;
4 listen 443 ssl;
5 ssl on;
6 server_name www.zfsphp.com;
7 index index.html index.htm index.php default.html default.htm default.php;
8 root /data/wwwroot/www.zfsphp.com;
9
10 ssl_certificate vhost/cert/214809029550588.pem;
11 ssl_certificate_key vhost/cert/214809029550588.key;
12 ssl_session_timeout 5m;
13 ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
14 ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
15 ssl_prefer_server_ciphers on;
16
17 include other.conf;
18 #error_page 404 /404.html;
19 location ~ [^/]\.php(/|$)
20 {
21 # comment try_files $uri =404; to enable pathinfo
22 try_files $uri =404;
23 fastcgi_pass unix:/tmp/php-cgi.sock;
24 fastcgi_index index.php;
25 include fastcgi.conf;
26 #include pathinfo.conf;
27 }
28
29 location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
30 {
31 expires 30d;
32 }
33
34 location ~ .*\.(js|css)?$
35 {
36 expires 12h;
37 }
38
39 access_log /home/wwwlogs/www.zfsphp.com.log access;
40 }
二 保存nginx配置文件并重启nginx服务即可
《Nginx配置同时支持http与https两种方式访问》上暂无评论!