VPS侦探论坛

 找回密码
 注册
查看: 3247|回复: 1

多个域名配置ssl,配置文件怎么设置

[复制链接]
发表于 2017-12-4 18:04:22 | 显示全部楼层 |阅读模式

服务器信息:centos7.4   64位   php7.1.2     

单个域名增加SSL已经搞定,实现了http://访问时自动跳转到https://,这样做的目的是无论用户是手动输入域名访问网站,默认都是http://,还是使用https://访问都保证网站可以打开,由于服务器上有多个网站使用了微信支付接口,而微信公众平台从2018年1月1日起,接口要求使用https://才能调用,所以不得不把网站改https://了。
单个网站搞定了,但多个域名配置SSL的时候就只有第一个配置的网站可以使用,其它的则用不了,麻烦军哥帮我看一下nginx的配置文件该怎么改,现在把单个网站配置SSL域名后自动跳转到https://的网站配置文件代码粘贴出来方便有http://跳转到https://需求的朋友解决跳转问题。

以下是需要增加到nginx.conf文件中的代码,直接放在nginx.conf最下面就可以,据说ssl on已经废除了,大家可以试一下。
server {
    listen 443;
    server_name www.lnmp.org;
    ssl on;
    root  /www/wwwroot/default;
    index index.html index.htm;
    ssl_certificate   /usr/local/nginx/conf/cert/214306099660183.pem;
    ssl_certificate_key  /usr/local/nginx/conf/cert/214306099660183.key;
    ssl_session_timeout 5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;

    location ~ [^/]\.php(/|$)

{

# comment try_files $uri =404; to enable pathinfo

try_files $uri =404;

fastcgi_pass  unix:/tmp/php-cgi.sock;

fastcgi_index index.php;

include fastcgi.conf;

#include pathinfo.conf;

}


location /nginx_status {

stub_status on;

access_log   off;

}


location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$

{

expires      30d;

}


location ~ .*\.(js|css)?$

{

expires      12h;

}
            access_log  /www/wwwlogs/access.log  access;
       }

include vhost/*.conf;
}


这下面的内容是vhost文件夹中网站配置文件的部分

server

{

listen 80;

#listen [::]:80;

server_name www.abc.com abc.com;

index index.html index.htm index.php default.html default.htm default.php;

root  /www/wwwroot/abc.com;
                return  301 https://$server_name$request_uri;

include ht.conf;

#error_page   404   /404.html;

location ~ [^/]\.php(/|$)

{

# comment try_files $uri =404; to enable pathinfo

try_files $uri =404;

fastcgi_pass  unix:/tmp/php-cgi.sock;

fastcgi_index index.php;

include fastcgi.conf;

#include pathinfo.conf;

}


location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$

{

expires      30d;

}


location ~ .*\.(js|css)?$

{

expires      12h;

}


access_log off;

}

server {
        listen 443;
        server_name abc.com www.abc.com;

        root  /www/wwwroot/abc.com;
        index index.html index.htm index.php;

        ssl on;
        ssl_certificate   /usr/local/nginx/conf/cert/214306099660183.pem;
        ssl_certificate_key  /usr/local/nginx/conf/cert/214306099660183.key;

        include ht.conf;

#error_page   404   /404.html;

location ~ [^/]\.php(/|$)

{

# comment try_files $uri =404; to enable pathinfo

try_files $uri =404;

fastcgi_pass  unix:/tmp/php-cgi.sock;

fastcgi_index index.php;

include fastcgi.conf;

#include pathinfo.conf;

}


location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$

{

expires      30d;

}


location ~ .*\.(js|css)?$

{

expires      12h;

}


access_log off;

}


单个网站这样配置应该是没问题的,但多个域名都要配置SSL,就不知道nginx.conf要怎么设置了,还往军哥多多指教,网上看了很多说法有点懵,虽然用了四年lnmp了,从1.1用到1.4,但还是小白一个,

[ 本帖最后由 bjwindy 于 2017-12-4 18:11 编辑 ]
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2017-12-5 11:34:36 | 显示全部楼层


ssl不是只写上个ssl on和证书key就行,不会的话可以直接 lnmp vhost add 或 lnmp ssl add 进行添加,具体查看官网教程 https://lnmp.org/faq/lnmp-vhost-add-howto.html
如何设置301 lnmp官网上 https://lnmp.org 也都有
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|VPS侦探 ( 鲁ICP备16040043号-1 )

GMT+8, 2024-3-19 16:36 , Processed in 0.025898 second(s), 16 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表