Python和Nginx问题

Python和Nginx问题,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/ngi

我正在尝试使用端口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;
}

谢谢

您需要删除
位置
块中的
索引
指令:

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;
}
索引
使nginx在代理传递发生之前查找索引。对其进行评论或删除将解决此问题

此外,也不需要
根目录。事实上,就是这样:

locatioin /static/ {
    proxy_pass   http://localhost:8080/
}

实际上,您可以使用Python模块在nginx中嵌入Python代码

404为什么?您只将
/static
传递给您的应用程序。我正在尝试传递一个html文件和一个像mudlol一样清晰的python.py文件。。对不起,我是Nginx的新手。。我有一个html文件,python服务器在8080端口上显示。我希望外部世界使用端口80和Nginx将其代理到端口8080。。希望您的帮助我的Nginx配置:。它可以与Gunicorn一起工作,但这并不重要——它与任何服务器的工作方式相同,因为它使用套接字进行连接?请记住,
proxy\u pass
将向您的应用程序发送
/static
,因此请记住您需要响应该URI。我对您提到的进行了调整。python web服务器conf是正确的,但是当我尝试代理它时,我仍然得到404 Not Found错误…python代码只是一个.py脚本,用于在端口80上运行python web服务器以说“Hello World”。我在日志中得到这个错误,[crit]2562#2562:*1 connect()到127.0.0.1:12891失败(13:权限被拒绝)连接到上游时,客户端:IP,服务器:localhost,请求:“GET/HTTP/1.1”,上游:,主机:“IP:80”哦,这是
selinux
-我刚禁用了selinux,因为它很烦人(不好的做法),但您也可以运行以下命令:
/usr/sbin/setsebool httpd\u can\u network\u connect true
这里: