Nginx 配置 SSL + 非443端口

配置 SSL+端口访问

在生产环境遇到这样一个问题,一个项目只给了一台服务器和一个域名,项目呢是有3个应用端,有两个前端应用用的是 VUE 开发,所以一个域名就显得不够用了,而且域名是配置了 SSL,前端应用是嵌入到企业微信应用中的,所以不担心用户记不住域名地址,就准备用 SSL +port 的方式来解决这个问题。以一个非 443 端口和443端口为例进行配置:

443 端口配置

server
{
    listen 80;
    listen 443 ssl http2;
    server_name www.domain.com;
    index index.php index.html index.htm default.php default.htm default.html;
    root /www/wwwroot/www.domain.com/;
    
    #SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
    #error_page 404/404.html;
    #HTTP_TO_HTTPS_START
    if ($server_port !~ 443){
        rewrite ^(/.*)$ https://$host$1 permanent;
    }
    #HTTP_TO_HTTPS_END
    ssl_certificate    /www/server/panel/vhost/cert/www.domain.com/fullchain.pem;
    ssl_certificate_key    /www/server/panel/vhost/cert/www.domain.com/privkey.pem;
    ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
    ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
    ssl_prefer_server_ciphers on;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 10m;
    add_header Strict-Transport-Security "max-age=31536000";
    error_page 497  https://$host$request_uri;
    #SSL-END

    access_log  /www/wwwlogs/www.domain.com.log;
    error_log  /www/wwwlogs/www.domain.com.error.log;
}

非 443 端口配置

server
{
    listen 4000 ssl http2;
    server_name work.firepa.vip;
    index index.php index.html index.htm default.php default.htm default.html;
    root /www/wwwroot/www.domain.com/other-port;
    
    #SSL-START SSL相关配置
    ssl_certificate    /www/server/panel/vhost/cert/www.domain.com/fullchain.pem;
    ssl_certificate_key    /www/server/panel/vhost/cert/www.domain.com/privkey.pem;
    ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
    ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
    ssl_prefer_server_ciphers on;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 10m;
    add_header Strict-Transport-Security "max-age=31536000";
    error_page 497  https://$host$request_uri;
    #SSL-END

    access_log  /www/wwwlogs/www.domain.com.other.port.log;
    error_log  /www/wwwlogs/www.domain.com.other.port.error.log;
}

你可能感兴趣的:(nginxssl)