I'm struggling at finding "best" (I know this is subjective, I'll explain in a minute) config for a nginx server.
My server is responsible of :
- Reverse proxying from 3 apps
- Delivering ssl certificates
and I'm looking for proxy config good practises for each case.
Here's the architecture
| Wordpress | wp.myhost.com
- | articles app |
/
/
/ | Complex |
http://myhost --- nginx ---- | node.js app | myapp.herokuapp.com
server \ | hosted on heroku |
^ \
NS record \
type A - | Simple node.js |
| homepage hosted | hp.herokuapp.com
| on heroku |
I'd like to have :
myhost.com
(aliased towww.myhost.com
)/
going to hp.herokuapp.commyhost.com
/articles
going to wp.myhost.commyhost.com
/app
going to myapp.herokuapp.com
Here's what I got working :
upstream herokuhp {
server hp.herokuapp.com:443;
}
upstream herokuapp {
server app.herokuapp.com:443;
}
upstream wordpress {
server wp.myhost.com:443;
}
server {
listen 80;
server_name myhost.com;
server_alias www.myhost.com;
rewrite ^(.*) https://$host$1;
}
server {
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/www.myhost.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/www.myhost.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
server_name myhost.com;
server_alias www.myhost.com;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
location ~ /articles {
proxy_pass https://wordpress;
}
location ~ / {
proxy_pass https://herokuhp;
}
location ~ /app {
proxy_pass https://herokuapp;
}
}
I now would like to get advices and best practises to optimize this piece configuration (regarding performance, SEO frienship, app updates awareness), mostly around caching, and buffering :)