這是我的 default.conf 檔案:
server {
listen 80;
listen [::]:80;
root /var/www/html/;
server_name example.com;
# Site 01
location /* {
alias /var/www/html/home/;
index index.htm index.php;
try_files $uri $uri/ /home/index.html;
}
# Site 2
location /shadows {
alias /var/www/html/shadows/;
index index.htm index.php;
try_files $uri $uri/ /shadows/index.php;
}
error_page 404 /error/404.php;
fastcgi_intercept_errors on;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}
}
我有一個 Codeigniter 應用程式
var/www/html/shadows
我也有一個 HTML 站點
var/www/html/home
問題:
我已經能夠為目錄 home 或 shadows 完成這項作業,但不能同時為這兩個目錄作業。
如果我將 root 更改為 /var/www/html/home,則會彈出 HTML 站點。
目前只有 shadows codeigniter 站點會彈出這個配置。
請讓我知道您對解決此問題的想法。非常感謝。
uj5u.com熱心網友回復:
如果我理解正確,這樣的事情應該有效:
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name example.com;
root /var/www/html/home;
location /shadows {
root /var/www/html;
index index.php;
}
}
/var/www/html/shadows/index.php在這種情況下,http://example.com/shadows/index.php將決議為路徑。
uj5u.com熱心網友回復:
您可以root通過map塊獲取指令值:
map $uri $approot {
~^/shadows/ /var/www/html;
default /var/www/html/home;
}
server {
listen 80;
listen [::]:80;
root $approot;
server_name example.com;
# Site 01
location / {
index index.htm index.php;
try_files $uri $uri/ /index.html;
}
# Site 2
location /shadows/ {
index index.htm index.php;
try_files $uri $uri/ /shadows/index.php$is_args$args;
}
error_page 404 /error/404.php;
fastcgi_intercept_errors on;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}
}
我假設您的 HTML 站點應該在根前綴下提供服務/,而不是/home/,因此我將您的try_files $uri $uri/ /home/index.html;指令更改為try_files $uri $uri/ /index.html;. 我也用你的alias指令替換了你的所有指令root。正如alias指令檔案所說
當 location 匹配指令值的最后一部分時:
location /images/ { alias /data/w3/images/; }最好使用該
root指令:location /images/ { root /data/w3; }
此外,當您將和指令一起使用時,還有一個眾所周知的錯誤,因此使用一個更可靠。aliastry_filesroot
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/344950.html
