I have two webapps on my server, the first one is WordPress and the second one is Laravel. I need my WordPress site to work on the TLD (domain.com) while the Laravel site to work on specific path (domain.com/path). Below is my nginx configuration:
server {
listen 80;
server_name domain.com www.domain.com;
root /home/domain/root3;
access_log /var/log/nginx/domain_access.log;
error_log /var/log/nginx/domain_error.log;
location / {
root /home/domain/root3;
index index.php index.html;
try_files $uri $uri/ /index.php?$args;
}
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
error_page 404 /index.php;
location /path {
alias /home/domain/laravel/public;
try_files $uri $uri/ /index.php?$query_string;
location ~ .php$ {
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
}
location ~ .php$ {
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass 127.0.0.1:9001;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
#fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location ~ /.ht {
deny all;
}
client_max_body_size 500M;
location /upstream {
proxy_ssl_server_name on;
try_files $uri $uri/ /index.php?$query_string;
}
}
Now when I try to access domain.com/path , I am getting 403 as below:
2023/05/17 17:30:49 [error] 26216#26216: *185 directory index of "/home/domain/laravel/public/" is forbidden, client: X.X.X.X, server: domain.com, request: "GET /path/ HTTP/1.1", host: "domain.com"
However, if I try to access domain.com/path/index.php the Laravel site works properly. Also please note that the WordPress site (domain.com) is working properly with no issues.
P.S.
All permissions and ownership checked and they are configured properly.
2
Answers
you can try the following steps:
Check directory permissions:
Ensure that the /home/domain/laravel/public directory and its contents have the correct permissions. The directory should be readable by the web server user. You can set the correct permissions using the following command:
sudo chmod -R 755 /home/domain/laravel/public
Update the Nginx configuration:
Modify the location /path block in your Nginx configuration as follows:
Restart Nginx:
I hope it helps
Updated
}
Assume your folder permissions set to correct.
This conf should be able to serve your Laravel in domain sub path perfectly and without affect by wordpress.