【发布时间】:2021-11-02 17:59:16
【问题描述】:
这是我的 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 站点使用此配置弹出。
请告诉我您对解决此问题的想法。非常感谢。
【问题讨论】:
-
“两个目录一个 URL” - 我不清楚你真正想要实现什么......你不能让一个 URL 指向两个位置......?
-
是的,我希望 www.url.com 指向位于 var/www/html/home 的 html 站点,并且我希望 url.com/shadows 指向 var/www/html/shadows阴影部分是我的 codeigniter 应用程序。
-
您的 PHP 处理程序
location ~ \.php$ { ... }使用您的默认根/var/www/html/,因此无法找到您的 Codeigniter PHP 文件。此外,将location /* { ... }更改为location / { ... }。您在/var/www/html/home的 HTML 站点是否也使用 PHP 文件? -
其中一些,是的。我在那里有一个无头 CMS。
-
@d7l2k4 已回答。当您在涉及超过两个人的讨论下撰写评论时,为确保您的评论将传送到正确的人员索引,请以用户名开始您的评论,例如
@IvanShatsky。我很容易错过你的回复。
标签: nginx nginx-config nginx-location