Python和Nginx问题

10 浏览
0 Comments

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日
0
0 Comments

您实际上可以使用 Python 模块https://github.com/arut/nginx-python-module将 Python 代码嵌入到 nginx 中。

0
0 Comments

你需要在你的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/
}

0