Answer the question
In order to leave comments, you need to log in
404 for routes or how to configure Nginx for subfolders?
There is a directory /var/www/example_com/
where the site is located example.com
.
From this directory, all routes work correctly, example.com/some_route,
example.com/users
, etc.
If I place the "second" site in sub directories, that is, I want something to come /var/www/example_com/sandbox/hello/
out of it example.com/sandbox/hello
, in which (!) I will redefine the routes, that is, the base path will be /sandbox/hello
and all routes will refer to index.php
in this folder, and not root.
Before that, I did this on shared hosting, everything worked as described, on vds I can’t configure the nginx config myself.
By the way, here is the config:
server {
listen 80;
listen [::]:80;
root /var/www/example_com;
index index.html index.php;
server_name example.com;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
Options -Indexes
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]
hello
, it gives a 404 error.
Answer the question
In order to leave comments, you need to log in
location /sandbox/hello/ {
try_files $uri $uri/ /sandbox/hello/index.php$is_args$args;
}
server {
listen 80;
listen [::]:80;
root /var/www/example_com;
index index.html index.php;
server_name example.com;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location /sandbox/hello/ {
try_files $uri $uri/ /sandbox/hello/index.php$is_args$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question