Python和Nginx问题
Python和Nginx问题
我正在尝试使用端口8080设置Python服务器,并让Nginx从端口80代理到8080。
现在我有
python -m SimpleHTTPServer 8080
正在运行,但出于某种原因我无法让Nginx代理它。我一直收到“404未找到”错误。(nginx/1.10.2)这是我在Nginx上的配置。
server { listen 80; server_name localhost; #charset koi8-r; #access_log /var/log/nginx/log/host.access.log main; location /static/ { # root /usr/share/nginx/html; root /home/ec2-user; index index.html index.htm; proxy_pass http://localhost:8080; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; }
谢谢
admin 更改状态以发布 2023年5月21日
你需要在你的location
块内删除index
指令:
server { listen 80; server_name localhost; #charset koi8-r; #access_log /var/log/nginx/log/host.access.log main; location /static/ { # root /usr/share/nginx/html; root /home/ec2-user; # index index.html index.htm; # It is looking for an index proxy_pass http://localhost:8080; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; }
index
会导致nginx在执行proxy_pass
之前寻找索引。注释或删除它将解决问题。
此外,root
也不是必需的,实际上只需要这样:
locatioin /static/ { proxy_pass http://localhost:8080/ }