
我需要配置 nginx,以便它從域子目錄上的不同文檔根目錄提供不同的軟體,如下所示:
http://example.com/... - main site from /var/www/main
http://example.com/docs/ - an independent application from /var/www/app
我嘗試了很多方法,包括 proxy_pass 和 alias,但沒有一個對我有用。最新配置如下:
server {
listen 80;
server_name example.com;
root /var/www/main;
index index.html;
location /docs/ {
root /var/www/app;
}
}
當我嘗試訪問時http://example.com/docs/我在 error_log 中看到 404 Not Found 錯誤和以下訊息:
*1“/var/www/app/docs/index.html”找不到(2:沒有這樣的文件或目錄
所以它嘗試打開/var/www/app/docs/index.html
而不是/var/www/app/index.html
.
rewrite
我知道這可以透過以下方式 解決rewrite ^/docs/(.*)$ /$1 last;
:它對我有用,但它也重寫了所有資產的所有相關鏈接,因此情況並非如此。
更新:
1)我的問題是alias
:
location /docs/ {
autoindex on;
alias /var/www/app/;
}
找不到“/var/www/app/index.html”(2:沒有這樣的檔案或目錄)
2)proxy_pass問題:
location /docs/ {
proxy_pass: http://127.0.0.1:8080;
}
...
server {
listen 8080;
server_name localhost;
root /var/www/app;
index index.html;
}
錯誤如下:
/var/www/app/docs/index.html" is not found (2: No such file or directory)