I am having a hard time trying to figure out how to configure Nginx. Basically, I have the same server name, but two websites:
- website x
root folder: /var/www/html/x/public
- Wordpress
root folder: /var/www/html/wordpress
When I access localhost:8443 it will go to: /var/www/html/x/public
when I access localhost:8443/blog it will go to: /var/www/html/wordpress
I managed to make it work up to a certain point where localhost:8443/blog works but localhost:8443/blog/my-blog-post doesn´t.
server {
listen [::]:443 ssl http2 ipv6only=on;
listen 443 ssl http2;
server_name localhost;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
charset utf-8;
index index.php;
root /var/www/html/exploraai/public;
location ^~ /blog {
alias /var/www/html/blog;
location ~ \.php$ {
try_files $uri = 404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri = 404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location ~ /\.(?!well-known).* {
deny all;
}
location = /favicon.ico {
access_log off; log_not_found off;
}
location = /robots.txt {
access_log off; log_not_found off;
}
}
I tried different things, but so far nothing worked.
Update
What worked for me was replacing the location blog for the following location block
location /blog {
alias /var/www/html/blog/;
try_files $uri /blog/index.php;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}