我将我的flask应用程序通过我的VM部署在Nginx上。
一切都已部署好,我可以在http://my.ip.number(我有一个公共IP)上请求我的api
但是当我运行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;
}
}
Host
标头设置为ngrok URL。 nginx的行为是尝试匹配上述配置中的server
块之一,如果没有server_name
匹配Host
标头,则默认为第一个。但是,我想在/etc/nginx/conf.d/default.conf
或/etc/nginx/sites-enabled/0-default
处还有另一个配置文件,该文件的listen
指令设置为default_server
。那将捕获这些请求并服务“欢迎使用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