I have a static website (MY_WEBSITE) and a php app (MY_PHP_APP) that I want to install in a server using nginx. I am still in the testing phase in localhost.
I am not too knowledgeable with nginx and I think I am doing something wrong.
I stored the website under /var/www/MY_WEBSITE (it contains an index.html file) and the php app under */var/www/MY_PHP_APP (it contains an index.php file). Read privileges and www-data user are correctly set up, and php8.1-fpm socket is installed.
This is my nginx configuration:
server {
listen 80 default_server;
listen [::]:80 default_server;
index index.php index.html index.htm index.nginx-debian.html;
server_name localhost;
location / {
root /var/www/MY_WEBSITE;
try_files $uri /index.html =404;
}
location /MY_PHP_APP {
root /var/www/MY_PHP_APP;
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
I can access my website under localhost, but I get 404 when I visit localhost/MY_PHP_APP. What I am doing wrong?
source https://stackoverflow.com/questions/77246388/serve-static-website-and-php-application-with-nginx
No comments:
Post a Comment