使用 1 个域名为多个端口设置 SSL 证书

时间:2021-05-02 02:35:40

标签: nginx nginx-config centos8

我需要为 2 个网站设置 ssl:admin 和 client,具有相同的域 abc.example.com 但不同的端口。

  1. 管理页面,您需要设置:
  • http:8080
  • https:8443
  • root /var/www/admin/public
server {
        listen 8080;
        server_name abc.example.com;
        root /var/www/admin/public;
        index index.php;
        error_log  /var/log/nginx/error.log;
        access_log /var/log/nginx/access.log;
        location ~ \.php$ {
           try_files $uri =404;
           fastcgi_split_path_info ^(.+\.php)(/.+)$;
           fastcgi_pass unix:/run/php-fpm/www.sock;
           fastcgi_index index.php;
           include fastcgi_params;
           fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
           fastcgi_param PATH_INFO $fastcgi_path_info;
         }

        location / {
           try_files $uri $uri/ /index.php?$query_string;
        }
    }

   server {
         listen 8443 ssl;
         server_name abc.example.com;
         root /var/www/admin/public;
         index index.php;
         error_log  /var/log/nginx/error.log;
         access_log /var/log/nginx/access.log;

         ssl_certificate /etc/pki/tls/certs/_example.com.crt;
         ssl_certificate_key /etc/pki/tls/certs/_example.com.key;
         location ~ \.php$ {
           try_files $uri =404;
           fastcgi_split_path_info ^(.+\.php)(/.+)$;
           fastcgi_pass unix:/run/php-fpm/www.sock;
           fastcgi_index index.php;
           include fastcgi_params;
           fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
           fastcgi_param PATH_INFO $fastcgi_path_info;
         }
    
        location / {
           try_files $uri $uri/ /index.php?$query_string;
        }
    }
  1. 客户端页面,您需要设置:
  • http:80
  • https:443
  • root /var/www/client/public
server {
        listen 80;
        server_name abc.example.com;
        root /var/www/client/public;
        index index.php;
        error_log  /var/log/nginx/error.log;
        access_log /var/log/nginx/access.log;
        location ~ \.php$ {
           try_files $uri =404;
           fastcgi_split_path_info ^(.+\.php)(/.+)$;
           fastcgi_pass unix:/run/php-fpm/www.sock;
           fastcgi_index index.php;
           include fastcgi_params;
           fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
           fastcgi_param PATH_INFO $fastcgi_path_info;
         }

        location / {
           try_files $uri $uri/ /index.php?$query_string;
        }
    }

     server {
         listen 443 ssl;
         server_name abc.example.com;
         index index.php;
         error_log  /var/log/nginx/error.log;
         access_log /var/log/nginx/access.log;
         ssl_certificate /etc/pki/tls/certs/_example.com.crt;
         ssl_certificate_key /etc/pki/tls/certs/_example.com.key;
         root /var/www/client/public;
         location ~ \.php$ {
           try_files $uri =404;
           fastcgi_split_path_info ^(.+\.php)(/.+)$;
           fastcgi_pass unix:/run/php-fpm/www.sock;
           fastcgi_index index.php;
           include fastcgi_params;
           fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
           fastcgi_param PATH_INFO $fastcgi_path_info;
         }
        
        location / {
          try_files $uri $uri/ /index.php?$query_string;
        } 
    }

我有上面的配置,80,443,8080端口连接成功,但8443端口不工作。虽然在服务器上我已经打开了8443端口。 enter image description here

具体来说,当我访问链接https://abc.example.com:8443/时,浏览器显示无法访问此站点 enter image description here

如果有人遇到这个问题并知道如何解决它。希望你能帮助我解决它。非常感谢!

0 个答案:

没有答案