nginx 配置多个 https 域名访问配置多ssl

wylc123 1年前 ⋅ 885 阅读

nginx.conf配置如下:

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;
    client_max_body_size 200m; #文件上传大小
    #gzip  on;
    #京拼科技官网
    server {
#监听80端口下的jp.daxueyiwu.com服务请求进行处理
        listen       80;
        server_name  home.daxueyiwu.com;
#rewrite ^(.*)$ https://$host$1 permanent;   #将所有http请求通过rewrite重定向到https。
        location / {
            root /usr/softs/apps/jphome;
            #默认请求转到root路径下的index.html页面。
    index index.html;
           
        }
    }
    #个人原创博客
    server {
listen       80;
server_name  www.daxueyiwu.com;
rewrite ^(.*)$ https://$host$1 permanent;   #将所有http请求通过rewrite重定向到https。
#charset koi8-r;

#access_log  logs/host.access.log  main;

location / {
client_max_body_size 200m; #文件上传大小
root   html;
index  index.html index.htm;
proxy_pass http://localhost:8080/;
}

#error_page  404              /404.html;

# redirect server error pages to the static page /50x.html
#
error_page   500 502 503 504  /50x.html;
location = /50x.html {
root   html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
#    proxy_pass   http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
#    root           html;
#    fastcgi_pass   127.0.0.1:9000;
#    fastcgi_index  index.php;
#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
#    include        fastcgi_params;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
#    deny  all;
#}
    }
#www.daxueyiwu.com https配置
server {
        listen       443 ssl;  #SSL协议访问端口号为443。此处如未添加ssl,可能会造成Nginx无法启动。
        server_name  www.daxueyiwu.com;  #将localhost修改为您证书绑定的域名,例如:www.example.com。
        ssl_certificate      cert/3498037_www.daxueyiwu.com.pem; #将domain name.pem替换成您证书的文件名。
        ssl_certificate_key  cert/3498037_www.daxueyiwu.com.key; #将domain name.key替换成您证书的密钥文件名。

        ssl_session_cache    shared:SSL:1m;
        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;
if ($scheme = http) {
return 301 https://$host$request_uri;
}
        location / {
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto https;
proxy_redirect off;
proxy_connect_timeout      240;
proxy_send_timeout         240;
proxy_read_timeout         240;
# note, there is not SSL here! plain HTTP is used
proxy_pass http://localhost:8080;
proxy_redirect http:// https://;
#proxy_set_header Upgrade $http_upgrade;  
#proxy_set_header Connection "upgrade";
        }
    }
    #个人原创博客www.songbin.top
    server {
                listen       80;
                server_name  www.songbin.top;
                rewrite ^(.*)$ https://$host$1 permanent;   #将所有http请求通过rewrite重定向到https。
                #charset koi8-r;

                #access_log  logs/host.access.log  main;

                location / {
                        client_max_body_size 200m; #文件上传大小
                        root   html;
                        index  index.html index.htm;
                        proxy_pass http://localhost:8088/;
                }

                #error_page  404              /404.html;

                # redirect server error pages to the static page /50x.html
                #
                error_page   500 502 503 504  /50x.html;
                location = /50x.html {
                        root   html;
                }

                # proxy the PHP scripts to Apache listening on 127.0.0.1:80
                #
                #location ~ \.php$ {
                #    proxy_pass   http://127.0.0.1;
                #}

                # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
                #
                #location ~ \.php$ {
                #    root           html;
                #    fastcgi_pass   127.0.0.1:9000;
                #    fastcgi_index  index.php;
                #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
                #    include        fastcgi_params;
                #}

                # deny access to .htaccess files, if Apache's document root
                # concurs with nginx's one
                #
                #location ~ /\.ht {
                #    deny  all;
                #}
    }
#www.songbin.top https配置
        server {
        listen       443 ssl;  #SSL协议访问端口号为443。此处如未添加ssl,可能会造成Nginx无法启动。
        server_name  www.songbin.top;  #将localhost修改为您证书绑定的域名,例如:www.example.com。
        ssl_certificate      cert/2728492_www.songbin.top.pem; #将domain name.pem替换成您证书的文件名。
        ssl_certificate_key  cert/2728492_www.songbin.top.key; #将domain name.key替换成您证书的密钥文件名。

        ssl_session_cache    shared:SSL:1m;
        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;
                if ($scheme = http) {
                        return 301 https://$host$request_uri;
                }
        location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                        proxy_set_header Host $http_host;
                        proxy_set_header X-Forwarded-Proto https;
                        proxy_redirect off;
                        proxy_connect_timeout      240;
                        proxy_send_timeout         240;
                        proxy_read_timeout         240;
                        # note, there is not SSL here! plain HTTP is used
                        proxy_pass http://localhost:8088;
                        proxy_redirect http:// https://;
                        #proxy_set_header Upgrade $http_upgrade;
                        #proxy_set_header Connection "upgrade";
        }
    }

    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}
更多内容请访问:IT源点

相关文章推荐

全部评论: 0

    我有话说: