Reputation: 11
I am working on a project where I need to set up Nginx as a reverse proxy on Windows Server 2022. My goal is to configure Nginx so that when users access a specific port (25400) on my server, they see the content from https://example.com, but with traffic routed through an external IP address instead of my server’s IP address.
What I have tried:
I have attempted to configure Nginx with the following settings:
Listening on port 25400 Proxying requests to https://example.com SSL configurations and various headers However, I am unsure how to ensure that the traffic to https://example.com is routed through the external IP address and not directly through my server’s IP.
How can I configure Nginx to achieve this setup where the content from https://example.com is routed through an external IP address?
Additional Details:
Nginx version: [your version here] External IP address: [provide the IP or note if not yet configured] Any guidance or examples would be greatly appreciated!
nginx.conf :
worker_processes 1;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
server {
listen 25400;
location / {
proxy_pass https://www.example.com;
proxy_buffers 8 16k;
proxy_buffer_size 32k;
proxy_ssl_server_name on;
proxy_ssl_verify on;
proxy_ssl_verify_depth 2;
proxy_ssl_trusted_certificate ca-certificates.crt;
proxy_ssl_certificate cert.pem;
proxy_ssl_certificate_key cert.key;
proxy_redirect off;
proxy_intercept_errors on;
proxy_hide_header Location;
proxy_hide_header Refresh;
proxy_hide_header Strict-Transport-Security;
proxy_cookie_domain www.example.com localhost;
proxy_cookie_path / /;
proxy_cookie_flags ~ Secure HttpOnly SameSite=None;
add_header Cache-Control "no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0";
add_header Pragma "no-cache";
add_header Expires "0";
sub_filter '<meta http-equiv="refresh"' '<!-- removed meta refresh -->';
sub_filter 'https://www.example.com' 'http://localhost:25400';
sub_filter_once off;
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Headers 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
add_header Access-Control-Expose-Headers 'Content-Length,Content-Range';
if ($request_method = OPTIONS) {
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Headers 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
add_header Access-Control-Max-Age 1728000;
return 204;
}
proxy_connect_timeout 120s;
proxy_read_timeout 300s;
proxy_send_timeout 300s;
gzip on;
gzip_types text/plain text/css application/javascript application/json application/xml text/xml text/javascript;
gzip_vary on;
proxy_buffering off;
}
location @no_redirects {
return 200 "Redirect Blocked!";
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
expires off;
add_header Cache-Control "no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0";
proxy_pass https://www.example.com;
proxy_hide_header Cache-Control;
}
location ~* \.svg$ {
proxy_pass https://www.example.com;
proxy_hide_header Cache-Control;
}
}
}
Upvotes: 1
Views: 139