I've searched the forums (and elsewhere on the web) and have found related but seemingly not identical information. Hopefully I'm not duplicating here.
I have a site running on an Apache server. It already has an SSL certificate (via LetsEncrypt) and runs without issue.
I've recently setup a machine 'in front' of it that is running Nginx. That machine serves three domains (with one certificate from LetsEncrypt).
I'd like to pass requests for the domain on the Apache machine through Nginx but am having trouble figuring out the proper settings. I've done this with two Apache serving machines in the past without much difficulty but I'm new to Nginx and clearly not sufficiently proficient with it yet.
The virtual server setup that I have on the Nginx net facing machine (through a router) is:
server {
listen domain.pointing.to.apache.com:443 ssl;
server_name domain.pointing.to.apache.com;
location / {
root 192.168.11.14/var/www/html/;
proxy_set_header X-Forwarded-Host $host:$server_port;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass domain.pointing.to.apache.com;
}
}
But, of course, Nginx does not like this and will not reload after adding the vs. Any advice etc. will be most appreciated.
Note - I guess it's obvious but 192.168.11.14 is behind my router and not exposed directly to the net.
Jason
Edit/Update:
Important info missing from my original inquiry:
The net facing Nginx machine that I want to reverse proxy to Apache is also serving three subdomains of my main domain that I want to reverse proxy (sub1.mydomain.com, sub2.mydomain.com, sub3.mydomain.com). All three share one SSL certificate from LetsEncrypt.
The Apache server on the local network had a LetsEncrypt issued certificate as well that was serving mydomain.com until I put the Nginx machine in front of it.
I have now deleted the SSL certs on the Apache machine, deleted the https virtual server and have a simple virtual server set up for port 80.
My default Nginx setting sends requests to http //www.mydomain.com which simply shares a very boring html page for now.
I've installed SSL certs for the domain https //www.mydomain.com on the Nginx box and want to use the recommendation provided by Tero to reverse proxy https requests on mydomain.com to and from the local Apache box. As follows:
server {
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/www.mydomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/www.mydomain.com/privkey.pem;
server_name www.mydomain.com;
location / {
proxy_set_header X-Forwarded-Host $host:$server_port;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass https://192.168.11.14;
}
}
The problem is I'm getting a 502 Bad Gateway error from the Nginx machine...so I guess I have something wrong with the Nginx settings...I'm getting close but not quite there. Additionally, I noticed that attempts to access www.mydomain.com without https no longer serves the boring html page...they get transferred/rewritten to https -> www.mydomain.com and to the same 502 bad gateway.