2017-04-13 192 views
1

我想反向代理我的NodeJS通過NGINX後端,但我不斷收到403禁止錯誤,nginx的記錄爲NGINX反向代理和靜態文件

[error] 10#10: *1 directory index of "/usr/share/nginx/html/" is forbidden, 
client: 172.20.0.1, server: localhost, request: "GET/HTTP/1.1", 
host: "localhost:8888 

我的服務器模塊配置:

server { 

    charset utf8; 
    listen 80 default_server; 

    location/{ 
     proxy_pass http://localhost:5000; 
     proxy_set_header Host $host; 
     proxy_set_header X-Real-IP $remote_addr; 
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
     proxy_cache_valid 200 1s; 
    } 

    location /assets/ { 
     expires 30d; 
     add_header Cache-Control "public"; 
     root /usr/share/nginx/html/; 
     try_files $uri =404; 
    } 
} 

經過一番研究,似乎它可能與NGINX identifying / as a query for a directory listing有關,並且很可能會要求我添加index index.html來解決問題(它沒有)。我的配置也匹配that presented by the official NGINX configurations反向代理。

有沒有人有一個想法如何解決這個問題?

任何幫助將不勝感激! 乾杯:)

+0

我不明白'localhost:8888'部分的錯誤信息。您還應該使用'nginx -T'測試您的配置。 –

+0

localhost:8888是我從中調用請求的主機。我不相信它與它有任何關係,但我的設置在docker中運行(請參閱此[docker-compose文件](https://github.com/futureboyHQ/website/blob/feature/6/docker/docker) -compose.yml))。儘管它沒有提供更多信息,但您可以在這裏找到'nginx -T'打印輸出(https://pastebin.com/HHAk1Kba)。 –

回答

1

它使用服務器localhost這是其他server塊。

您問題中的server塊是默認服務器,但另一個塊具有明確的server_name localhost語句,該語句優先。

您應該刪除另一個服務器塊,以便只有一個服務器塊,它將始終使用。

問題文件位於/etc/nginx/conf.d/default.conf

server塊的選擇在this document中解釋。

+0

太棒了!這絕對解決了我的問題!我通過添加'RUN RM -f的/ etc/nginx的/ conf.d/default.conf'命令到nginx的dockerfile施加的溶液。乾杯:D –