Nginx多站点部署


在公司初创的过程中,为了降低基础资源的费用投入,会采用将不同的web应用程序或网站部署在同一台服务器上的情况,不同的业务通过不同的二级域名独立的进行维护,这样虽然业务的时间地址为同一台机器,却可以通过不同的域名访问独立的隔离业务。

通过端口来区分业务功能

对于面向终端用户的端口一般为80/443,通过同一台设备的nginx,我们可以再通过部署其它端口的配置,来实现通过单台服务器后台与前台的统一应用,如下:

 server {               #对外服务部分
                listen 80 default_server;
                listen [::]:80 default_server;
                root <your website root path>;
                index index.html index.htm;
                server_name _;
                location / {
                }
        }
 server {            #对内管理服务部分
               listen 443 ssl;

               ssl_certificate      /etc/letsencrypt/live/itkengzhu.ignorelist.com/fullchain.pem;
               ssl_certificate_key  /etc/letsencrypt/live/itkengzhu.ignorelist.com/privkey.pem;

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

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

                root /opt/wordpress;

                index index.html index.htm;

                server_name _;

                location / {
                        proxy_pass http://127.0.0.1:10000;
                        proxy_set_header Host $http_host;
                }
        }

通过域名配置来区分业务功能

由于面向终端用户均为80/443端口,因此,细分的业务类型需要通过域名的方式进行区分,配置模式如下:

 server {
        listen       80;
        listen       [::]:80;
        server_name  <level two domain name>;
        root         <domain name reletive website root path>;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/php.conf;

        location / {
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

   server {
         listen       80;
         listen       [::]:80;
         server_name  <another level two domain name>;
         root         <domain name reletive website root path>;

         # Load configuration files for the default server block.
         include /etc/nginx/default.d/dockerphp.conf;

         location / {
             include /etc/nginx/default.d/rewrite.conf;
         }

         error_page 404 /404.html;
             location = /40x.html {
         }

         error_page 500 502 503 504 /50x.html;
             location = /50x.html {
         }
    }

   server {
         listen       80;
         listen       [::]:80;
         server_name  _; #default website
         root         <default website root path>;

         # Load configuration files for the default server block.
         include /etc/nginx/default.d/dockerphp.conf;

         location / {
             include /etc/nginx/default.d/rewrite.conf;
         }

         error_page 404 /404.html;
             location = /40x.html {
         }

         error_page 500 502 503 504 /50x.html;
             location = /50x.html {
         }
    }
, ,

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注