Last active
November 5, 2020 04:37
-
-
Save geekforbrains/01df7c31fd62f84f453b8bc22217f3c6 to your computer and use it in GitHub Desktop.
Nginx reverse proxy for Heroku
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
upstream heroku { | |
server myapp.herokuapp.com; | |
} | |
server { | |
server_name ~^(www\.)(?<domain>.+)$; | |
return 301 $scheme://$domain$request_uri; | |
} | |
server { | |
listen 80 default; | |
listen 443 ssl; | |
#server_name _; | |
ssl off; | |
ssl_certificate /etc/nginx/ssl/myapp.com.crt; | |
ssl_certificate_key /etc/nginx/ssl/myapp.com.key; | |
location ~ \.php$ { | |
return 444; | |
} | |
location / { | |
proxy_pass http://heroku; | |
proxy_redirect off; | |
proxy_read_timeout 5m; | |
proxy_set_header Host $http_host; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-Proto http; | |
} | |
} |
I'm trying to serve two nodejs apps on Heroku.
One on app.example.com and one on example.com.
I setup the DNS via cloudflare correctly (but I've used CNAME).
I've added nginx from https://elements.heroku.com/buildpacks/heroku/heroku-buildpack-nginx
I'm stuck with configuring the nginx file (first time when touching it). I feel that I'm close, but I'm not sure where to place this code, as yours.
@george-i As per the link :
You can provide your own NGINX config by creating a file named
nginx.conf.erb
in the config directory of your app
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is so you can use a custom domain with an
A
record as apposed to anALIAS
orCNAME
. This can be helpful when building a product that allows an end user to map their own custom domain. AnA
record is much easier for them to do (and doesn't forcewww.
)