Ngrok 没有正确隧道 Nginx
Ngrok not tunneling properly Nginx
我通过我的 VM 在 Nginx 上部署了我的 Flask 应用程序。
一切都已部署好,我可以在 http://my.ip.number 上请求我的 api(我有一个 public IP)
但是当我 运行 Ngrok(我需要 https 并且我没有域名来生成 SSL 证书)时,URL https//number.ngrok.io 显示 Nginx 主页(欢迎使用 Nginx)而不是我的 webapp。
为什么会这样?
P.D: 当我 运行 "curl localhost" 我得到 Nginx 欢迎页面但是当我执行 "curl -4 localhost" 我得到我的 webapp 主页
etc/nginx/site-available/myproject
server {
listen 80;
server_name 0.0.0.0;
location / {
include proxy_params;
proxy_pass http://unix:/home/datascience/chatbot-cima/chatbot.sock;
}
}
server {
listen 80;
server_name 127.0.0.1;
location / {
proxy_pass http://unix:/home/datascience/chatbot-cima/chatbot.sock;
}
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://unix:/home/datascience/chatbot-cima/chatbot.sock;
}
}
server {
listen 80;
server_name public.ip;
location / {
proxy_pass http://unix:/home/datascience/chatbot-cima/chatbot.sock;
}
}
来自 ngrok 的任何请求都将 Host
header 设置为 ngrok URL。 nginx 的行为是尝试匹配上面配置中的 server
块之一,如果没有 server_name
匹配 Host
header,则默认为第一个块。
不过,我猜测在 /etc/nginx/conf.d/default.conf
或 /etc/nginx/sites-enabled/0-default
处还有另一个配置文件,其中包含一个 listen
指令和 default_server
集。这将捕获这些请求并为 "Welcome to nginx!" 页面提供服务。
我建议您查找该文件并将其删除,这应该可以解决问题。
不过你也可以简化上面的配置,只需要:
server {
listen 80;
server_name localhost;
location / {
include proxy_params;
proxy_pass http://unix:/home/datascience/chatbot-cima/chatbot.sock;
}
}
如果没有另一个 server
块隐藏在配置中的其他地方,并且带有像 listen 80 default_server;
这样的指令,那么这应该捕获所有请求。
有关详细信息,请参阅:How nginx processes a request
我通过我的 VM 在 Nginx 上部署了我的 Flask 应用程序。
一切都已部署好,我可以在 http://my.ip.number 上请求我的 api(我有一个 public IP)
但是当我 运行 Ngrok(我需要 https 并且我没有域名来生成 SSL 证书)时,URL https//number.ngrok.io 显示 Nginx 主页(欢迎使用 Nginx)而不是我的 webapp。
为什么会这样?
P.D: 当我 运行 "curl localhost" 我得到 Nginx 欢迎页面但是当我执行 "curl -4 localhost" 我得到我的 webapp 主页
etc/nginx/site-available/myproject
server {
listen 80;
server_name 0.0.0.0;
location / {
include proxy_params;
proxy_pass http://unix:/home/datascience/chatbot-cima/chatbot.sock;
}
}
server {
listen 80;
server_name 127.0.0.1;
location / {
proxy_pass http://unix:/home/datascience/chatbot-cima/chatbot.sock;
}
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://unix:/home/datascience/chatbot-cima/chatbot.sock;
}
}
server {
listen 80;
server_name public.ip;
location / {
proxy_pass http://unix:/home/datascience/chatbot-cima/chatbot.sock;
}
}
来自 ngrok 的任何请求都将 Host
header 设置为 ngrok URL。 nginx 的行为是尝试匹配上面配置中的 server
块之一,如果没有 server_name
匹配 Host
header,则默认为第一个块。
不过,我猜测在 /etc/nginx/conf.d/default.conf
或 /etc/nginx/sites-enabled/0-default
处还有另一个配置文件,其中包含一个 listen
指令和 default_server
集。这将捕获这些请求并为 "Welcome to nginx!" 页面提供服务。
我建议您查找该文件并将其删除,这应该可以解决问题。
不过你也可以简化上面的配置,只需要:
server {
listen 80;
server_name localhost;
location / {
include proxy_params;
proxy_pass http://unix:/home/datascience/chatbot-cima/chatbot.sock;
}
}
如果没有另一个 server
块隐藏在配置中的其他地方,并且带有像 listen 80 default_server;
这样的指令,那么这应该捕获所有请求。
有关详细信息,请参阅:How nginx processes a request