网站首页> 文章专栏> Nginx配置多个站点(.Net)
Nginx配置多个站点(.Net)
日期:2021-07-24 19:01:00 作者:jzlnice 浏览量:245

1、在Nginx配置目录下,新建一个“vhost”目录,假定Nginx的配置目录是“/usr/local/nginx”;


mkdir /usr/local/nginx/vhost
2、创建网站A的配置文件


vim /usr/local/nginx/vhost/vhost_siteA.conf


3、添加配置文件(假定网站A配置了https)


server {

        listen       80;
        server_name  www.siteA.com;
        rewrite ^(.*)$ https://$host$1 permanent;
}

server {
        listen       443 ssl;
        server_name  www.siteA.com;

        ssl_certificate      /usr/local/nginx/.../www.siteA.com.pem;
        ssl_certificate_key  /usr/local/nginx/.../www.siteA.com.key;
        ssl_session_timeout 5m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #按照这个协议配置
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;#按照这个套件配置
        ssl_prefer_server_ciphers on;
        ssl_session_cache    shared:SSL:1m;

        location / {
            proxy_pass http://localhost:XXX;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection keep-alive;
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
4、同样网站A,新建网站B配置文件



vim /usr/local/nginx/vhost/vhsot_siteB.conf
5、添加如下配置(假定网站B不配置http)



server {
        listen       80;
        server_name  www.siteB.com;
        location / {
            proxy_pass  http://localhost:xxxx;
            proxy_http_version  1.1;
            proxy_set_header  Upgrade $http_upgrade;
            proxy_set_header  Connection keep-alive;
            proxy_set_header  Host $http_host;
            proxy_cache_bypass  $http_upgrade;

        }
6、打开nginx.conf文件
vim /usr/local/nginx/conf/nginx.conf
7、将虚拟目录加入将虚拟目录的配置文件加入到”http {}”部分的末尾
http {
    ...
    include /etc/nginx/vhost/*.conf;
}
8、重启nginx服务
cd /usr/local/nginx/sbin
./nginx -t
./nginx -s reload



来说两句吧
最新评论
    热门文章
      随便看看