子目錄我需要的子域轉換到子目錄像abc.example.com => example.com/abc,我讀了nginx的論壇,並試圖通過代理與配置如下:NGINX:子域,而無需重新定向
abc.example.com nginx的配置文件:
location/{
proxy_pass http://example.com/abc;
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_set_header X-Forwarded-Proto $scheme;
}
example.com nginx的配置文件:
upstream example {
least_conn;
server ip_addr_1:port;
server ip_addr_2:port;
}
server {
listen 80;
server_name example.com;
return 301 https://example.com$request_uri;
}
server {
listen 443;
server_name example.com
root /var/www/test/public_html;
index index.html index.htm;
ssl on;
ssl_certificate /etc/nginx/ssl/example.com.chained.crt;
ssl_certificate_key /etc/nginx/ssl/example.key;
location/{
proxy_pass http://example;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
配置文件的作品,但它與控制檯錯誤打開空白頁爲:
Uncaught SyntaxError: Unexpected token <
我認識到,對於像/ API和/ CSS調用,它是由如下
example.com/api
example.com/css
,而不是與abc.example.com:
abc.example.com/api
abc.example.com/css
所以在我如上所述更改配置文件後,如果我嘗試打開abc.example.com而不是獲取example.com/abc,則會得到example.com的主頁。
總體:需要幫助,使他們的子域映射到SUBPATH /子目錄不chaning的URL(redirection(重定向)關閉)和/ API和/ CSS應在頂部被稱爲(根)域。
感謝您耐心閱讀整個問題並幫助解決問題!
P.S. 我修改了配置如下:paste。我們能夠獲得保留爲abc.example.com的URI映射,但無法刪除/ abc。所以,出現的URI是abc.example.com/abc,而我們只需要它就是abc.example.com。總之,需要幫助擺脫從客戶端出現的URL額外的/abc。
但是,我必須從nginx的靜態補充一點,你可能需要服務器/ CSS。 – cnst
感謝回答!我試着用你提到的配置。鏈接abc.example.com仍然會將我帶到example.com的主頁,而不是我們在** proxy-pass **中傳遞的example.com/abc。 – manishrw
它必須是導致問題的上游配置;您可能希望使用可選的http://nginx.org/r/sub_filter模塊以確保所有引用都已更改 – cnst