nginx 端口转发

测试nginx端口转发

环境:ubuntu 18.04 LTS(cat /etc/issue)
1.安装python3(默认安装)
2.安装pip (apt-get install python-pip)
3.安装虚拟环境venv(apt-get install python-venv)
4.新建flask工程(文件夹)
__flask-app
|__main.py
|__main1.py
|__venv
5.创建虚拟环境(python3 -m venv ./venv)
6.进入虚拟环境(source /venv/bin/activate)
7.编辑main.py和main1.py

# main.py
from flask import Flask

app = Flask(__name__)

@app.route('/one/')
def index():
    return 'this is on port 5000'

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000)

# main1.py
from flask import Flask

app = Flask(__name__)

@app.route('/two/')
def index():
    return 'this is on port 5001'

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5001)

8.安装screen(apt-get install screen)
9.新建screen shell
(screen -S flask-5000/5001)
执行python3 main.py/main1.py
10.screen相关命令
Ctrl+A+D 退出screen shell
screen -ls
screen -r [id.name]
11.安装nginx(apt-get install nginx)
nginx相关位置:
/etc/nginx/配置文件
/usr/sbin/可执行命令
12.修改nginx配置文件/etc/nginx/nginx.conf

http {
        access_log /etc/nginx/log/access.log;
        error_log /etc/nginx/log/error.log;
        
        server {
                listen 9999;
                server_name 0.0.0.0;
                
                location /one/ {
                    proxy_pass http://127.0.0.1:5000;
                }

                location /two/ {
                    proxy_pass http://127.0.0.1:5001;
                }
        }        
}

13.验证nginx格式(nginx -t)
14.启动nginx(systemctl start nginx... service start nginx)
15.查看nginx状态(systemctl status nginx... service status nginx)
16.重新加载nginx配置文件(nginx -s reload)

17.测试
服务器IP:X.X.X.X

http://X.X.X.X:9999/one/
return 'this is on port 5000'
http://X.X.X.X:9999/two/
return 'this is on port 5001'

你可能感兴趣的:(nginx 端口转发)