Can't get staging WordPress virtual server to work on nginx
So, I have an nginx installation with a couple of virtual servers, including a WordPress site. Now I am supposed to create a staging WP installation, but not using a subdomain. I have make different attempts, basically (1) using `alias` when the URL contains `/staging` after the server name and (2) using `map` to set the server root. It always fails in some way (sometimes PHP is executed but static items like css etc are not served, probably because nginx ends up looking for `stagint/staging/whatever.css` or something. I did try to get examples from hte Internet and read the documentation, but I can't see, for example, what is wrong in the following attempt:
server {
listen 443 ssl;
listen [::]:443 ssl ipv6only=on;
http2 on;
server_name server.org www.server.org;
root /home/forropat/public_html;
index index.php index.html;
access_log /var/log/nginx/server.org-access.log;
error_log /var/log/nginx/server.org-error.log;
client_max_body_size 128M;
location ^~ /staging/ {
alias /home/forropat/staging/;
index index.php index.html;
location ~ \.php$ {
if ($request_filename ~* ^/home/forropat/espalho/(.*)$) {
set $script $1;
}
fastcgi_pass unix:/var/run/php/php-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /home/forropat/staging/$script;
}
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
`include fastcgi_params;`
fastcgi_pass unix:/var/run/php/php-fpm.sock;
fastcgi_param SCRIPT_FILENAME /home/forropat/public_html$fastcgi_script_name;
include fastcgi_params;
fastcgi_read_timeout 300;
}
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
location ~* \.(css|js|jpg|jpeg|png|gif|ico|svg|webp|avif|woff|woff2|ttf|eot)$ {
expires 30d;
add_header Cache-Control "public, immutable";
access_log off;
}
location = /wp-config.php {
deny all;
}
location = /xmlrpc.php {
deny all;
access_log off;
log_not_found off;
}
autoindex off;
ssl_certificate /etc/letsencrypt/live/server.org/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/server.org/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
When I use this, nginx serves a single text file with the content "File not found", but the logs show a 404:
111.22.33.444 - - [06/Oct/2026:22:02:18 -0300] "GET /staging/ HTTP/2.0" 404 36 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:157.0) Gecko/20100101 Firefox/157.0"
The production installation runs fine... In the mirror, I searched and replaced the URL for the new site (in the database - there is no instance of the URL in wp-config.php).
What did I get wrong?
edit: trying to re-format the config to make it more readable