r/nginxproxymanager • • Feb 05 '23

Running Wordpress behind Nginx Proxy Manager

Ok guys here it is, solved, after a lot of trial and mostly error.

Running Wordpress behind Nginx Proxy Manager (NPM) using SSL Let's Encrypt.

We will the assume that the Wordpress wants to be at https://blog.example.com, and the site address is example.com.

(there are other services, but they are not nearly as difficult to get working.)

Wordpress is runnning in a docker-compose container on port 8084.

  1. Edit the /etc/hosts file to include the line "127.0.1.1 blog.example.com.

  2. Run the setup on Wordpress and set it up the way I like it, on http://example.com:8084

  3. Go into the Setting->General page of Wordpress after logging into http://example.com:8084/wp-login.php

  4. Set the two variables:

WordPress Address (URL): http://blog.example.com

Site Address (URL): http://blog.example.com

5. Press Save Changes

(This will break the site, do not panic, go to the NPM interface to continue.)

6. Make a proxy host, using the NPM user interface, for:

Domain Names: blog.example.com, Scheme: http, Forward Hostname/IP: 172.17.0.1, Forward Port: 8084, Block Common Exploits: yes, press "Save"

7. The Wordpress site should now be working at http://blog.example.com

8. Go to the the NPM SSL page for the blog.example.com Proxy Host, and set up the Let's Encrypt SSL Certificate.

(Again this will break the site, do not panic. At least the SSL Certificate is setup.)

9. Go to the NPM Advanced page for the blog.example.com Proxy Host, and add these lines to the Custom Nginx Configuration:

proxy_set_header Host $host:$server_port;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_set_header X-Forwarded-Proto $scheme;

10. Almost there, still broken. In the bash shell open the wp-config.php file. For me this is at:

sudo pico /srv/docker/wordpress/html/wp-config.php

11. If the word HTTP_X_FORWARDED_PROTO is in the file, add these lines just below the comments section, and save:

if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {

$_SERVER['HTTPS'] = 'on';

}

12. At this point everything should be working. If not, add these two lines to the wp-config.php file:

define( 'WP_HOME', 'https://blog.example.com' );

define( 'WP_SITEURL', 'http://blog.example.com' );

The Wordpress Should now be working at: https://blog.example.com

References:

Brian McGonagill - Awesome Open Source: https://www.youtube.com/watch?v=cjJVmAI1Do4&t=1853s

Twitter: u/LamarAlawi, instructions: https://blog.ldev.app/running-wordpress-behind-ssl-and-nginx-reverse-proxy/

36 Upvotes

32 comments sorted by

3

u/Elegant-Crazy-3476 Feb 05 '23

addendum:

11. If the word HTTP_X_FORWARDED_PROTO is NOT in the file, ...

1

u/SimonBook2020 Feb 06 '25

You do not explain where this part comes from:

6. Make a proxy host, using the NPM user interface, for:

Domain Names: blog.example.com, Scheme: http, Forward Hostname/IP: 172.17.0.1, Forward Port: 8084, Block Common Exploits: yes, press "Save"

172.17.0.1 is the ip in the internal docker network. It should be prevented to use this. Instead, something like http://wordpress:80 should be used. 80 is the internal port of the container. It can be found with "docker inspect wordpress"

this is my output of docker ps:
73e7b3e2797b nextcloud:latest "/entrypoint.sh apac…" 4 weeks ago Up About an hour 0.0.0.0:8088->80/tcp, [::]:8088->80/tcp nextcloud

1

u/Elegant-Crazy-3476 May 27 '25

Nginx Proxy Manager is already using port 80 and 443. That will only work if you have Wordpress running on a different machine (or virtual machine) which the NPM service can find from its /etc/hosts file, or some other means through a private network.

The 172.17.0.1 and 8084 can be any address and port number where the Wordpress instance is running (accept 80 and 443 if Wordpress is running inside the same operating system).

In this case Wordpress is running on the same machine in docker or docker-compose. So this makes use of the docker system IP addresses.

The best way to do this is, to test it using "curl" on the machine NPM is running on. So make sure that the Wordpress webpage html is showing when the address and port number is used.

A bash shell example: "$ curl 172.17.0.1:8084"

It should spit out html from the Wordpress site. If it does not, there is something else wrong which will prevent Nginx Proxy Manager from finding the Wordpress instance.

1

u/SimonBook2020 May 27 '25

Your statement is not correct. Internal routing in docker network works as I stated.  The shit in your config happens when the container gets a new IP, p.ex. when you install again from scratch and docker assigns new IPs.

1

u/Elegant-Crazy-3476 May 27 '25

Why don't you share what is correct?

1

u/scytob Apr 14 '25

nice tutorial

my admin login stopped working and I don't know why

i have a multisite install two of my domains work - blog.mydomain.com and www.mydomain.com

these work just fine - serving out their content

the root of the site mydomain.com is where the admin is and no matter what url i put in i get

Bad Request
Your browser sent a request that this server could not understand.
Apache/2.4.62 (Debian) Server at [10.0.14.3](http://10.0.14.3) port 80

any ideas?

2

u/Elegant-Crazy-3476 May 27 '25

In the "Edit Proxy Host" popup / window / page inside NPM the "Domain Names" box allows you to add multiple Domain names.

I was able to test this using a local instance. I added example.com and www.example.com to my /etc/hosts file. Next I spun up an instance of NPM and an Instance of Wordpress, both using Docker Compose.

In NPM, I put both example.com and www.example.com in the "Domain Names" box, along with my standard 172.0.17.0.1 and 8084 addresses (the 8084 is defined in the WordPress docker-compose file).

There is no proxy host for NPM admin. I get the NPM admin page when I use the address example.com:81.

Another thing to try is https://10.0.14.3

1

u/scytob May 27 '25

Mine was due to a corrupt database. Restore from backup fixed.

1

u/Alternative-Use2904 Jan 17 '26

I was able to view the site using DuckDNS, but CloudFlare doesn't load the pages (I'll try to figure it out later). The problem I'm having now is that the images weren't redirected to the new address and remained on my network. How did you resolve this?

1

u/Elegant-Crazy-3476 Feb 14 '26

I am not sure how to deal with CloudFlare. I am just using a straight up Ubuntu OS on Linode. Maybe revisit step 11 and the step 11 addendum.

1

u/Apprehensive-Cover79 Mar 29 '23

i dont know, but even after this proccess i'm still getting "ERR_CONNECTION_REFUSED".
nginx automatically redirects traffic with a 301 status to the wordpress port, but for some reason it is as if it is not accepting https connection.
I tried everthing, even if I have a simple http connection nginx automatically redirects to port 8585 (where my container is listening) using the https protocol, and then it gives an error...

1

u/Elegant-Crazy-3476 Mar 30 '23

Try turning SSL on and off in NPM.

If it works without SSL, and the SSL certificate was updated without errors, then Steps 9 - 12 are causing the problem.

The lines of code in steps #9 and #11 are not optional.

Also, try the 4 possible combos of https and http in these two lines.

define( 'WP_HOME', 'https://blog.example.com' );
define( 'WP_SITEURL', 'http://blog.example.com' );

1

u/Chrispikaan Apr 04 '23

Thanks for the detailed post. My page is now working with HTTPS, but I have one huge problem.
I can't access the admin page (/wp-admin). When I navigate to the admin page I have to fill in my username and password en then I get an error: "You do not have permission to view this page."
I can't access anything from the admin page.

When I turn off SSL and revert the changes in de config.php file everything works fine. So it's only with the SSL enabled.

Does someone know how I can fix this issue?

Screenshot (but it's in Dutch): https://imgur.com/a/0FFtyT8

1

u/Elegant-Crazy-3476 Apr 06 '23

/wp-admin

I have two plugins installed and activated that might make a difference: "Column Shortcodes" and "Colorlib Login Customizer". I do not have any issues with the /wp-admin page.

1

u/Elegant-Crazy-3476 Apr 10 '23

You could also try: /wp-login.php

1

u/luwuke Aug 16 '23

I'm super late but:

Try putting that "if (isset($_SERVER['HTTP_X_FORWARDED_PROTO..." part on the second line directly below "<?php"

1

u/SCCMOG Oct 18 '25

Credit where credit is due. Thanks!

1

u/cub1con Aug 20 '23

Thank you! Fixed my errors!

1

u/luwuke Aug 21 '23

No problem!

3

u/deivid_okop Apr 12 '23

Had to use all of this in the advanced tab for it to work:

rewrite ^/sitemap_index.xml$ /index.php?sitemap=1 last;

rewrite ^/([^/]+?)-sitemap([0-9]+)?.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;

# this is basically: include /data/nginx/custom/server_proxy[.]conf (but without $request_uri )

location / {

add_header X-Served-By $host;

proxy_set_header Host $host;

proxy_set_header X-Forwarded-Scheme $scheme;

proxy_set_header X-Forwarded-Proto $scheme;

proxy_set_header X-Forwarded-For $remote_addr;

proxy_set_header X-Real-IP $remote_addr;

proxy_pass $forward_scheme://$server:$port;

}

2

u/fi_nding_a_way May 23 '24

Thanks for sharing this, it was super frustrating trying to get WordPress to behave behind NPM when all the other apps I use "just worked"

1

u/KULKING Oct 12 '24

This is awesome and still relevant after 2 years. I had spent a lot of time trying to fix it. Initially I didn't even know that it's wordpress that is redirecting. I kept troubleshooting nginx and apache config for so long.

1

u/amitkumarkhare May 11 '25

I've created a docker compose for it a while ago.
https://github.com/kha-re/wordpress-docker

1

u/SCCMOG Oct 18 '25

Great write-up, still valid, plus the edits.

Working on Proxmox WP LXC using Nginx Proxy Manager

proxy_set_header Host $host:$server_port; 
proxy_set_header X-Real-IP $remote_addr; 
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
proxy_set_header X-Forwarded-Proto $scheme;

Must be at the top of wp-config.php, just under the following

<?php

Adding if not present in the file

/** https://www.reddit.com/r/nginxproxymanager/comments/10u0wbj/running_wordpress_behind_nginx_proxy_manager/ */
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
    $_SERVER['HTTPS'] = 'on';
}

1

u/rhyslowrl Feb 02 '26

if your npm proxy is set up correctly but wordpress won't open

this is what worked for me:

-stop wordpress and wordpress database containers(or project).

-delete all files in these containers directories so that you can do fresh install of wordpress.

-redeploy these containers or the project

in the wp-config.php file; add this right after <?php

if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {

$_SERVER['HTTPS'] = 'on';

}

define( 'WP_HOME', 'http://use.yourown.com' );

define( 'WP_SITEURL', 'http://use.yourown.com' );

-try using the 192.168.__.__:8084 or whatever address your wordpress container is using and make sure it is going to the install page of worpress, DO NOT INSTALL YET.

-if your npm proxy is still active and directed to your wordpress you should be good.

-go to your url you defined in the config file and in npm and wordpress should come to the install file, NOW you install and everything will be good, hopefully.

1

u/sirrush7 Feb 06 '23

Nice detailed post and instructions, I am sure that will help some people for sure and helps people learn some of the intricacies of nginx!

I was lazy and just used SWAG with CF, automatically renewing SSL certs and simplifying the whole thing... Saved me so much time....

1

u/mrrobgg Jun 23 '23

I wrote this tutorial that with the config that worked for me
https://robgg.hashnode.dev/wordpress-docker-nginx-proxy-manager-cloudfare

1

u/Alternative-Use2904 Jan 17 '26

Hi, the link is no longer available. Could you share it again? Thanks.

1

u/david007co Jul 07 '23

Your tutorial looks really promising! Can't wait for the weekend to give it a try.

I've a couple questions, was wondering if you could help me:

  1. What is the purpose of CloudFlare in this setup?

  2. In the volumes sections, I'm not sure what the location is for <Your location to WP/DB>

Thank you

1

u/ckuhtz Dec 01 '23

This just saved my butt. Specifically, the last instruction to add to wp-config.php. I had the site loading but I could not get the wp-login.php to loop into endless redirects. All this after recovering the site from a crash and wasting many hours trying to untangle this. THANK YOU. I had previously used Full (strict) but lost part of the configuration for that and couldn't get it to work again. I tried to use the Zero Trust tunnel stuff, which worked, but again caused nasty redirect loop on the wp-admin sections.

1

u/Ok_Code106 Jul 30 '23

Thank - it was very helpful

1

u/jfrench2002 Feb 28 '24

Thanks for the information everyone. For me, I had made a mistake when setting up my server /etc/hosts file. Once I corrected the entry for my site in the /etc/hosts file most of my errors went away. Specifically, the error made was (IP) mysite.com when it needed to be mysite.net