Question

nginx proxy_pass doesn't work in wordpress admin and returns 404

Posted February 9, 2020 523 views
Nginx

i have a main domain that is exampel.net and a blog service to name wp-exampel.site.cloud
i need to open blog with this url : exampel.net/blog so
i did this in my nginx :

location ^~ /blog {

        rewrite /blog/(.*) /$1  break;
        proxy_http_version 1.1;
       proxy_set_header Host $http_host;
        proxy_request_buffering off; # Disable any internal request  bufferring.
        proxy_pass http://wp.lunato;
        server_name_in_redirect off;
     #   proxy_set_header Host $host:$server_port;

    }

it works fine when i open exampel.com/blog

but when i try to use admin of wordpress the /blog remove from url
it’s ok when i open exampel.net/blog/wp-admin
but /blog will remove when i open exampel.net/wp-admin/.edit.php or other pages in menu of wordpress admin

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

Hello,

If you would like the Wordpress installation to be accessible via exampel.net/blog/ you need to set your Wordpress site and home URLs to exampel.net/blog. That way your wp-admin menu would take you to the correct page.

Hope that this helps!
Regards,
Bobby

  • hey Bobby tnx for ur help but i’ve already did it my site and home url both are example.net/blog but i still got this funny probelm :(

    • Hi @mavahidmarali,

      What is the exact error that you are seeing? Is your reverse proxy setup to pass the traffic back to Apache at the backend? If you only have Nginx, then you don’t really need the reverse proxy setup.

      Regards,
      Bobby

      • i’m using two container to name app and WP
        app is the main site and Wp is the wordpress which is used for blog
        lunato.net is the app service
        wp-lunato.fandogh.cloud is the wp service
        i proxied wp-lunato.fandogh.cloud to /blog in my app nginx

        location ^~ /blog {
        
                rewrite /blog/(.*) /$1  break;
                proxy_http_version 1.1;
               proxy_set_header Host $http_host;
                proxy_request_buffering off; # Disable any internal request bufferring.
                proxy_pass http://wp.lunato;
                server_name_in_redirect off;
             #   proxy_set_header Host $host:$server_port;
        
            }
        

        lunato.net/blog works fine but in the admin panel of wordpress all links returns 404 cos urls changes to lunato.net/wp-admin
        and it returns 404
        do u have any idea ?

        • Hi @mavahidmarali,

          Your config looks correct, I think that it might be the config of your Wordpress container. Can you share your Apache configuration that you have inside your container and your .htaccess file as well?

          Regards,
          Bobby

        • Hi @mavahidmarali,

          Can you try with the following:

          <IfModule mod_rewrite.c>
          RewriteEngine on
          RewriteCond %{HTTP_HOST} ^(www.)?example.com$
          RewriteCond %{REQUEST_URI} !^/blog/
          RewriteCond %{REQUEST_FILENAME} !-f
          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteRule ^(.*)$ /blog/$1
          RewriteCond %{HTTP_HOST} ^(www.)?example.com$
          RewriteRule ^(/)?$ blog/index.php [L] 
          </IfModule>
          

          I’ve got this from the official Wordpress documentation here.

          Let me know how it goes!
          Regards,
          Bobby

Submit an Answer