nginx如何连接多个服务?

记录一下:

刚开始用nginx部署,在项目文件内touch了一个nginx.conf配置文件,然后将这个conf文件软链接到nginx的工作目录中

sudo ln -s /home/ubuntu/xx/nginx.conf /etc/nginx/conf.d/

原本以为每次创建一个flask项目,都需要创建一个nginx文件,每次都要软链接,在没有同时部署的时候,确实看不出问题;

问题是:如果同时需要开启2个,3个,4个服务在同一个服务器上,那么需要创建那么多nginx文件么,而且还会有一些其他想不到的问题。

后来百度了一下,才发现是那么的简单,有多少个服务,只需要在nginx后面加多少server就完事了,e.g:

server {
    listen 8090;
    server_name 192.168.66.66;          # 服务器公网ip

    location / {
        proxy_pass http://127.0.0.1:9999;      #这个是Gunicorn与Ningx通信的端口。和Gunicorn的配置相同
        access_log /home/flaskweb/access.log;
        error_log  /home/flaskweb/error.log;
    }
}


server {
    listen 9090;
    server_name 192.168.77.77;          # 服务器公网ip

    location / {
        proxy_pass http://127.0.0.1:9091;      #这个是Gunicorn与Ningx通信的端口。和Gunicorn的配置相同
        access_log /home/flaskweb/access.log;
        error_log  /home/flaskweb/error.log;
    }
}

......

记录一下工作中的问题。

原文地址:https://www.cnblogs.com/aidenzdly/p/10974577.html