I am trying to direct all HTTPS traffic to Nginx server where it will handle all the requests as HTTP requests to all internal servers. So far, I am able to get the template below to work for most of my servers.
server {
listen 443 default ssl;
ssl_certificate /etc/letencrypt/live/somesite.com/fullchain.pem;
ssl_certificate_key /etc/letencrypt/live/somesite.com/privkey.pem;
server_name somesite.com;
location ^~ /Service {
proxy_pass http://192.168.1.2;
}
location / {
proxy_pass http://192.168.1.3;
}
}
However, I am restricted to always having to match up https://somesite.com/Service with http://192.168.1.2/Service in order for the above to work.
I can't have https://somesite.com/Service to work with http://192.168.1.2/Hello.
Or that I can't direct this to other port like https://somesite.com/Service with http://192.168.1.2:3000.
For instance, when I changed the above to this:
location /Service/ {
proxy_pass http://192.168.1.2:80/;
}
location / {
proxy_pass http://192.168.1.3;
}
Using the following logging setup:
log_format upstreamlog '[$time_local] $remote_addr - $remote_user - $server_name to: $upstream_addr: $request upstream_response_time $upstream_response_time msec $msec request_time $request_time';
access_log /var/log/nginx/access.log upstreamlog;
This is the log I got:
[22/Jan/2021:09:56:28 +0000] 172.56.38.95 - - - somesite.com to: 192.168.1.2:80: GET /Service/ HTTP/1.1 upstream_response_time 0.004 msec 1611309388.445 request_time 0.004
[22/Jan/2021:09:56:28 +0000] 172.56.38.95 - - - somesite.com to: 192.168.1.2:80: GET /Service/js/default.cache.a331c8c3.js HTTP/1.1 upstream_response_time 0.000 msec 1611309388.547 request_time 0.002
[22/Jan/2021:09:56:28 +0000] 172.56.38.95 - - - somesite.com to: 192.168.1.2:80: GET /Service/favicon.ico HTTP/1.1 upstream_response_time 0.012 msec 1611309388.757 request_time 0.012
[22/Jan/2021:09:56:28 +0000] 172.56.38.95 - - - somesite.com to: 192.168.1.3:80: GET /api/v1/oauth.json?_=1611309389573 HTTP/1.1 upstream_response_time 0.016 msec 1611309388.771 request_time 0.017
It can be seen that from the log that the first three fetches are correct. The fourth one is wrong. No further request was made afterward. After tracing a bit more, I realize that 192.168.1.2 already has a Nginx server running and processing PHP pages using FastCGI. I don't know if that makes a difference or not.
So I tried using rewrite in combination of what I have above, but I ran into a Page Not Found. I presume that it doesn't seem to work for HTTPS maybe? Thus, it led me to asking the question of how to configure Nginx to reverse proxy with URL rewrite and HTTPS externally.