Nginx(10) nginx 配置多个server,多个端口

14 篇文章 0 订阅

现在同一linux服务器配置其端口的服务,拟用已经运行 的nginx来配置

步骤如下

创建一个配置文件  比如  /usr/local/nginx/sites-available/gaotianyue.conf

upstream gaotianyue.com{
        server 127.0.0.1:8070 weight=1;
    }
    server {
        listen       8071;
        server_name  localhost;

        location / {
            proxy_http_version 1.1;
            proxy_pass http://gaotianyue.com;
            proxy_redirect default;
            proxy_connect_timeout 1s;
            proxy_read_timeout 5s;
            proxy_send_timeout 2s;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            add_header 'Access-Control-Allow-Headers' 'Content-Type';
            add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Allow-Methods' 'GET';
        }

        location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css|mp3|mp4)$
        {
             root /data/gaotianyue/static_src;
             expires      14d;
        }

         error_page  404   /404.html;
         error_page  404   /404.html;
         location = /404.html{
          root   html;
        }

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

修改nginx.conf

最后一个括号前添加

  include /usr/local/nginx/sites-available/*.conf;
}

然后检查下

[root@VM_126_4_centos nginx]# sbin/nginx -t -c conf/nginx.conf
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

最后重启

sbin/nginx -s reload


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值