I need to place a site inside existed project. site.com – this is the main site, site.com/site2/ this is the second one.
- When I visite site.com it’s show me /index.php [OK]
- When site.com/site2/ it’s show me /site2/web/index.php [OK]
- But when site.com/site2/qwe it redirect back to /index.php [FAIL]. I need /site2/web/index.php
The project structure is:
/
/site2/
/site2/web/
/site2/web/index.php
/index.php
Nginx site conf
server {
root /var/www/site;
index index.php index.html index.htm;
...
location / {
try_files $uri $uri/ =404;
}
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}
location /site2/ {
alias /var/www/site/site2/web/;
add_header X-Location-Visited true always;
try_files $uri $uri/ /index.php$is_args$args;
# I'd tried without any result
# try_files $uri $uri/ /site2/index.php$is_args$args;
# try_files $uri $uri/ /site2/web/index.php$is_args$args;
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}
}
}
snippets/fastcgi-php.conf
# regex to split $uri to $fastcgi_script_name and $fastcgi_path
fastcgi_split_path_info ^(.+?.php)(/.*)$;
# Check that the PHP script exists before passing it
try_files $fastcgi_script_name =404;
# Bypass the fact that try_files resets $fastcgi_path_info
# see: http://trac.nginx.org/nginx/ticket/321
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;
fastcgi_index index.php;
include fastcgi.conf;