1,在服务器1中安装flask,gunicorn,nginx
2,在服务器1中加入文件myapp.py
from flask import Flask, request, json, jsonify
app = Flask(__name__)
@app.route('/test', methods=['POST'])
def test():
return "hello world"
if __name__ == '__main__':
app.debug =True
app.run()
3,在服务器1中输入下述命令启动myapp
/usr/local/bin/gunicorn -w 4 -b 127.0.0.1:8000 myapp:app
4,修改服务器1nginx配置文件
vim /etc/nginx/nginx.conf
vim /etc/nginx/sites-enabled/default
vim /etc/nginx/sites-available/default
加入
server {
listen 80;
server_name 119.23.239.132;
client_max_body_size 10M;
location / {
proxy_pass http://127.0.0.1:8000;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
5,在服务器1中运行
service nginx start
nginx -s reload
6,通过http调用得到内容“hello world”
https://www.sojson.com/httpRequest/
7,在服务器2上安装nginx
8,修改服务器2的nginx配置文件
vim /etc/nginx/nginx.conf
加入
server {
listen 80;
server_name 47.106.111.53;
client_max_body_size 10M;
location / {
proxy_pass http://119.23.239.132:80;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
9,在服务器2中运行
service nginx start
nginx -s reload
网友评论