I'm trying to get my Wordpress site to serve from example.com/blog with an Nginx web server proxy_pass to a Wordpress site (apache) hosted on another server at blog.site.com.

With my current Nginx config viewing the blog from site.com/blog is working fine, however, I'm unable to access the login for the Wordpress site. It seems like it may be falling through to the ~. .php location but I'm unsure how to prevent that behavior.

For example, when I attempt https://example.com/blog/wp-admin it returns a 404 from https://example.com/wp-admin/

If I try https://example.com/blog/wp-admin/ it gives me a stdErr of No input file specified from https://example.com/blog/wp-login.php?redirect_to=https%3A%2F%2Fexample.com%2Fblog%2Fwp-admin%2F&reauth=1

Nginx Config for example.com -

map $uri $expires {
    default off;
    ~\.(jpg|jpeg|png|gif|ico|css|js|pdf)$ 7d;

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name site.com;
    root /var/www/example.com/current/public;

    ssl_certificate /etc/nginx/ssl/site.com/454191/server.crt;
    ssl_certificate_key /etc/nginx/ssl/site.com/454191/server.key;

    ssl_protocols TLSv1.2;
    ssl_prefer_server_ciphers on;
    ssl_dhparam /etc/nginx/dhparams.pem;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        expires $expires;
        try_files $uri $uri/ /index.php?$query_string;

    location /blog/ {
        proxy_pass https://blog.example.com/;
        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;
    error_log  /var/log/nginx/example.com-error.log error;

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;

    location ~ /\.(?!well-known).* {
        deny all;
  • If you intend to serve WordPress from a different URL, you need to tell WordPress about this. – Michael Hampton Dec 13 '18 at 17:58
  • In my wp-config.php file on the Wordpress site, I have example.com/blog defined for both WP_HOME and WP_SITEURL. Is this what you are referring to? – Adam M. Dec 13 '18 at 18:34
  • You need to use location ^~ /blog/ otherwise any URI ending with .php will be processed by your location ~ \.php block and not WordPress. – Richard Smith Dec 13 '18 at 19:40

Per the comments, this change solved the problem.

location ^~ /blog/ {
        proxy_pass https://blog.example.com/;
        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.