Here is my default.conf file:
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;
}
}
I have a Codeigniter app in
var/www/html/shadows
I also have a HTML site in
var/www/html/home
The issue:
I have been able to make this work for the directories home or shadows but not both.
If I change root to /var/www/html/home the HTML site pops up.
Currently just the shadows codeigniter site pops up with this configuration.
Please let me know your thoughts on resolving this. Thank you very much.
2
Answers
If I understand you correctly, something like this should work:
http://example.com/shadows/index.php will resolve to path
/var/www/html/shadows/index.php
in this case.You can get the
root
directive value via themap
block:I’m assuming your HTML site should be served under the root prefix
/
, not the/home/
, therefore I changed yourtry_files $uri $uri/ /home/index.html;
directive to thetry_files $uri $uri/ /index.html;
. I also replaced all youralias
directives withroot
ones. As it said by thealias
directive documentationAdditionally there is a well-known bug when you are using
alias
andtry_files
directives together, so using theroot
one instead is more reliable.