I am running a local web app on my dev machine. And I want to reach my local web app from a test machine (a phone).
I set up Nginx to listen on port 8888. My test machine can reach my dev machine at this port.
Requests that should go the local web application are reverse-proxied from port 8888 to the local web app port 3000. These requests work fine.
Requests that should go to the internet are forward-proxied and resolved by 8.8.8.8. But these requests can only be HTTP. Nginx does not seem to be able to handle forward-proxy HTTPS requests.
This setup for HTTP works:
server {
listen 8888;
listen [::]:8888;
server_name local.myapp.be myapp.com;
access_log /var/log/nginx/myapp/access.log;
error_log /var/log/nginx/myapp/error.log;
location / {
proxy_pass http://local.myapp.be:3000;
proxy_redirect http://local.myapp.be:3000 $scheme://$host:8888;
proxy_set_header Host $host;
}
}
server {
listen 8888 default_server;
listen [::]:8888 default_server;
access_log /var/log/nginx/default/access.log;
error_log /var/log/nginx/default/error.log;
location / {
resolver 8.8.8.8;
proxy_pass http://$http_host$uri$is_args$args;
}
}
I then tried removing the second server block and adding this to nginx.conf at http block level:
stream {
resolver 8.8.8.8;
server {
listen 8888;
ssl_preread on;
proxy_connect_timeout 5s;
proxy_pass $ssl_preread_server_name:$server_port;
}
}
But that does not seem to work.
How can I setup an Nginx proxy to handle both reverse-proxy and forward-proxy (http & https) requests correctly?