我想連接domain.com/c到/var/www/a/c和。我撰寫了 nginx 站點可用檔案,如下所示:domain.com/b/var/www/b
server {
listen 443 ...
index index.php index.html;
server_name domain.com;
root /var/www/a;
location / {
try_files $uri $uri/ =404;
}
location /b {
root /var/www/b;
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.0-fpm.sock;
}
}
但是當我進入時我看到 404 domain.com/b。我嘗試使用alias而不是,root但我得到了相同的結果。我能怎么做?
uj5u.com熱心網友回復:
這是因為你location ~ \.php$ { ... }使用你的 global root /var/www/a;。這只是許多其他解決方案中的兩個可能的解決方案:
使用嵌套的 PHP 處理程式:
server { listen 443 ... index index.php index.html; server_name domain.com; root /var/www/a; location / { try_files $uri $uri/ =404; } location ^~ /b/ { root /var/www; try_files $uri $uri/ /b/index.php?$query_string; location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php8.0-fpm.sock; } } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php8.0-fpm.sock; } }或者,如果您
/var/www/b是唯一的 PHP 應用程式,您可以root向您的 PHP 處理程式添加一個指令:server { listen 443 ... index index.php index.html; server_name domain.com; root /var/www/a; location / { try_files $uri $uri/ =404; } location /b/ { root /var/www; try_files $uri $uri/ /b/index.php?$query_string; } location ~ \.php$ { root /var/www; include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php8.0-fpm.sock; } }使用該
map指令從請求 URI 中獲取您的 Web 根目錄:map $uri $root { ~^/b/ /var/www; default /war/www/a; } server { listen 443 ... index index.php index.html; server_name domain.com; root $root; location / { try_files $uri $uri/ =404; } location /b/ { try_files $uri $uri/ /b/index.php?$query_string; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php8.0-fpm.sock; } }
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/428584.html
上一篇:在fpm/pool.d/website-name.confNGINX上改變用戶有多大的損害
下一篇:如何使用NGINX托管多個Create-React-App生產構建,每個構建在一個單獨的目錄中(沒有Docker)
