步骤一,启动ngrok
ngrok by @inconshreveable (Ctrl+C to quit)
Session Status online
Session Expires 6 hours, 27 minutes
Version 2.3.35
Region United States (us)
Web Interface http://127.0.0.1:4040
Forwarding http://8323eeb5.ngrok.io -> http://localhost:80
Forwarding https://8323eeb5.ngrok.io -> http://localhost:80
Connections ttl opn rt1 rt5 p50 p90
1 0 0.00 0.00 14.62 14.62
HTTP Requests
-------------
GET /favicon.ico 404 NOT FOUND
GET / 200 OK
步骤二,
# nginx -c /etc/nginx/nginx.conf
# nginx -s reload
python hello.py
浏览器访问:
得到:
#---------------------------------------------------附录----------------------------------------------------------------------------
hello.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello World!'
if __name__ == '__main__':
app.run(host="127.0.0.1",port=10071)
nginx.conf
user root;
worker_processes 2;
error_log /etc/nginx/error.log;
pid /etc/nginx/nginx.pid;
events {
worker_connections 1024;
}
http {
#include /usr/local/nginx/conf/mime.types;
include /etc/nginx/mime.types;
default_type application/octet-stream;
server {
listen 80;
server_name 8323eeb5.ngrok.io;
access_log /var/log/nginx/access.log;
location / {proxy_pass http://127.0.0.1:10071;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}
location /static {
root /home/appleyuchi;
autoindex on;}
location /media {
root /home/appleyuchi;
autoindex on; }
}
}