Score:1

Unable to make right URL structure with NGINX proxy

ru flag

I have two application. One is a nextjs app and another is a WordPress app. Both are running in difference instances.

In order to serve my WordPress blog from my main site like https://example.com/blog, I have added the following proxy to my main site's nginx server configuration,

location ^~ /blog/ {
    http2_push_preload on;
    proxy_pass https://blog.exmaple.com/;
    proxy_http_version 1.1;
    proxy_set_header Host blog.example.com;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_cache_bypass $http_upgrade;
}

If I click on any save button from the admin portal, then it removes the 'blog' word from the URL on next load like this 'https://exmaple.com/wp-admin/options-general.php?settings-updated=true' and gives a 404 in main site when it should be like 'https://example.com/blog/wp-admin/options-general.php?settings-updated=true'.

I have updated the WordPress URLs as well. And all other URLs such as homepage, blog posts, page, media etc. are working find.

What am I doing wrong here? Please feel free to ask for more information for clarification.

Hasan avatar
ru flag
Even though the issue on this question (https://serverfault.com/questions/944231/nginx-proxy-pass-to-wordpress-site-for-site-com-blog-to-blog-site-com) is similar to my issue (not exactly same), the said solution in this isn't working either. Please help.
in flag
Go to WordPress General Settings and change the URL, as described in the [Moving WordPress documentation](https://wordpress.org/documentation/article/moving-wordpress/#changing-your-domain-name-and-urls)
Hasan avatar
ru flag
The URL are already changed and I also updated the wp-config file.
in flag
Then please provide all relevant information, don't let people guess blindly.
Hasan avatar
ru flag
It was missed by mistake.
Hasan avatar
ru flag
I can now access the home page. After using the solution mentioned in the question I linked in my first comment, it worked. It was my browser cache at that moment that made me think the homepage was not accessible. So, I have updated the question accordingly to the problem that is present now.
Score:1
ru flag

Here's what I did as workaround,

I redirected any https://example.com/wp-admin to https://example.com/blog/wp-admin with this change in my nginx conf,

location /wp-admin {
    rewrite ^/wp-admin(/.*)?$ /blog/wp-admin$1 permanent;
}

PS: Somehow I feel its not the best thing to do but only thing I could do for now. I hope someone will come up with a better solution.

djdomi avatar
za flag
please mark it as resolved, or we will reminded for ever to solve this
Hasan avatar
ru flag
Okay. Marking it now but somehow it still doesn't feel right.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.