# Nginx Reverse Proxy and Cloudflare

**URL:** <https://forum.ghost.org/t/nginx-reverse-proxy-and-cloudflare/30653>\
**Category:** Developer help\
**Created:** [June 6, 2022, 7:23pm UTC](https://forum.ghost.org/t/nginx-reverse-proxy-and-cloudflare/30653 "2022-06-06T19:23:59Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![mjw](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/mjw/32/30781_2.png) [@mjw](https://forum.ghost.org/u/mjw)\
**Post date:** [June 7, 2022, 10:49am UTC](https://forum.ghost.org/t/nginx-reverse-proxy-and-cloudflare/30653/5 "2022-06-07T10:49:52Z")

</div>

> [@jake1](#):
>
> I feel like I’m quite close but I’m just not 100% sure what values I should be using on Cloudflare / Nginx Proxy Manger / the site.conf file under sites-enabled folder.

Using `ghost install` correctly will set this up for you out-of-the-box. However, you seem to be doing something different to the guide, e.g., using Nginx Proxy Manager, which isn’t needed.

> [@jake1](#):
>
> Happy to start over if it’s helpful but not sure what I will have done differently as I have been using nginx from the start as opposed to Apache like the other post.

If you read the thread (from the post I referenced) you will understand that the first part of the thread was rolling back, so a clean installation could take place.

> [@jake1](#):
>
> If I start over, when Ghosts asks me if I want to install nginx is there any benefit to installing this if I’m using a separate reverse proxy?

Ghost doesn’t install Nginx–it is a prerequisite–but it does configure the site an SSL for the given domain. Moreover, Nginx is a reverse proxy.

Ghost runs on the local host, e.g. `127.0.0.1:<some port>` and Nginx is used to proxy this to http or https (recommended.) http is port 80 whereas http is on port 443; these ports are exposed to the Internet whereas the Ghost port is not.

> [@jake1](#):
>
> UFW - not enabled…

You need to harden any server that is accessible to the Internet, more so with an application such as Ghost that can be set up as a bulk mailer. However, it looks like you are using a VM on your home network, so this should already be behind a firewall in your router; just make sure 80 and 443 are open and forwarded to the VM.

> [@jake1](#):
>
> Output from mariadb / mysql below

You are using MySQL, not MariaDB. This is an important distinction since Ghost only supports MySQL 8.0.

> [@jake1](#):
>
> If I set NPM scheme to https, forward port to 443 and proxy pass to port 80 under NPM advanced nginx config then I get a message to say there are too many redirects. I realise I probably don’t want to pass port 80 but like I said i’ve been trying just about every different combination I can think of!
> 
> The rest of the time, I normally get a 502 bad gateway Cloudflare page to say there’s a problem on my server end.

This is to be expected since you have a broken Nginx configuration.

If you haven’t already used Ghost, I think the best option is to start over. The thread I posted covers this for Ubuntu 20.04. The only difference is the OP wanted Ghost V4 whereas you can install V5 by omitting the `4.48.1`,

To tidy up Nginx, remove the symbolic links to the Ghost site in `/etc/nginx/sites-enabled` and delete the borked configuration file in `/etc/nginx/sites-available`. Ignore or uninstall Nginx Proxy Manager since it is unnecessary.

You’ll almost certainly need to clear cookies in your web browser to prevent the unwanted redirects reoccurring.

Edit: I note your root domain is resolving fine. If you want to use Cloudflare instead of ACME (Let’s Encrypt etc.) then you’ll need to set up Cloudflare Origin Server certificates including a certificate request (CSR), and manually configure Nginx. If you’ve set up your root domain certificate with a wildcard, you may use this. Please reach out to me, and I can give you the Nginx configuration, since this is how I handle SSL.

---

_[View the full topic](https://forum.ghost.org/t/nginx-reverse-proxy-and-cloudflare/30653)._
