Question

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

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


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Bobby Iliev
Site Moderator
Site Moderator badge
February 10, 2020
Accepted 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

I tried your solution, even though admin page is showing but login form is not working,

My Code

upstream blog{
    server wordpress:80;
}

upstream client{
    server frontend:8080;
}


server{
    listen 80;

    location / {
        proxy_pass http://client;
    }

# to enable hot reloading 
    location /sockjs-node {
        proxy_pass http://client;

        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
    }

    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://blog;
        server_name_in_redirect off;# I tried by commenting it out but nothing works
     #   proxy_set_header Host $host:$server_port;

    }


 
}


Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.