2016-12-06 46 views
1

我使用的是8080端口試圖安裝一個python服務器並nginx的以代理從80端口爲8080Python和Nginx的問題

現在我有

python -m SimpleHTTPServer 8080 

運行,但對於一些原因我無法讓Nginx代理它。我不斷收到「404 Not Found」錯誤。 (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; 
} 

謝謝

+0

404爲了什麼?你只是將'/ static'傳遞給你的應用程序。 – jordanm

+0

我試圖通過一個html文件和一個python .py文件 – Devon

+0

這就像泥漿一樣清晰 – jordanm

回答

1

您需要刪除您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使得在proxy_pass發生前的指數nginx的樣子。評論或刪除它將解決問題。另外,也不需要root。只是這實際上是:

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

你能用Python代碼更新你的問題嗎?請記住'proxy_pass'會發送'/ static'到你的應用程序,所以請記住你需要響應這個URI。 – varlogtim

+0

我做了你提到的調整。 python web server conf是正確的,但是當我嘗試代理它時,我仍然收到404 Not Found錯誤... – Devon

+0

python代碼只是一個.py腳本,用於在端口80上運行Python Web服務器來說「Hello World 」。 – Devon