嘗試讓 nginx 代理我的 node.js 應用程式並使用它的網域。我將把許多網域映射到伺服器,因此我.conf
為每個伺服器區塊使用單獨的檔案。我現在遇到的問題是,當我進入網域時,我似乎只能顯示預設的 nginx 頁面。我將盡力盡可能清楚地解釋當前的設置,如果您需要更多信息,請告訴我。
nginx.conf 更改
我將根路徑設定為我的應用程式檔案所在的位置,root /var/www;
因此,例如,應用程式將部署到資料夾/var/www/example.com
。
伺服器塊配置
我為伺服器區塊創建了一個新文件,/etc/nginx/conf.d/example_com.conf
其中包含
server
{
listen 80;
listen [::]:80;
server_name example.com www.example.com;
location /var/www
{
proxy_pass http://localhost:3103;
include /etc/nginx/proxy_params;
}
}
請注意,前往我的http://myip:3103按應有的方式呈現應用程序,並且文件/etc/nginx/proxy_params
包含
proxy_buffers 16 32k;
proxy_buffer_size 64k;
proxy_busy_buffers_size 128k;
proxy_cache_bypass $http_pragma $http_authorization;
proxy_connect_timeout 59s;
proxy_hide_header X-Powered-By;
proxy_http_version 1.1;
proxy_ignore_headers Cache-Control Expires;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504 http_404;
proxy_no_cache $http_pragma $http_authorization;
proxy_pass_header Set-Cookie;
proxy_read_timeout 600;
proxy_redirect off;
proxy_send_timeout 600;
proxy_temp_file_write_size 64k;
proxy_set_header Accept-Encoding '';
proxy_set_header Cookie $http_cookie;
proxy_set_header Host $host;
proxy_set_header Proxy '';
proxy_set_header Referer $http_referer;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Original-Request $request_uri;
我在這裡做錯了什麼嗎?您需要更多資訊嗎?請告訴我! nginx 對我來說相當新,我覺得我已經非常接近了,我只是注意到理解了一些東西。謝謝!
答案1
location 指令指定客戶端請求 URI,而不是本機檔案系統上的檔案位置。
所以location /var/www {
意味著當有人請求時使用這個位置www.example.com/var/www
嘗試將其更改為location / {