Is someone willing to tell me how to get this config to work?
# Define separate upstream blocks for IPv4 and IPv6 backend servers
upstream backend_ipv4_ht1 {
server 192.168.0.1:1080;
}
upstream backend_ipv6_ht1 {
server [2a02:8070:5181:25a0:da3a:ddff:fe28:17b]:1080;
}
upstream backend_ipv4_ht2 {
server 192.168.0.1:2080;
}
upstream backend_ipv6_ht2 {
server [2a02:8070:5181:25a0:da3a:ddff:fe28:17b]:2080;
}
# Map $remote_addr to the appropriate backend based on IP version
map $remote_addr $backend_ht1 {
~[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+ backend_ipv4_ht1;
default backend_ipv6_ht1;
}
map $remote_addr $backend_ht2 {
~[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+ backend_ipv4_ht2;
default backend_ipv6_ht2;
}
# HTTP and HTTPS server block for ht1.example.net
server {
listen 443 ssl;
listen [::]:443 ipv6only=off;
server_name ht1.example.net;
ssl_certificate /etc/letsencrypt/live/example.net/cert.pem;
ssl_certificate_key /etc/letsencrypt/live/example.net/privkey.pem;
ssl_protocols TLSv1.3;
location / {
# Proxy to the appropriate backend based on the client's IP version
proxy_pass http://$backend_ht1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
# HTTP and HTTPS server block for ht2.example.net
server {
listen 443 ssl;
listen [::]:443;
server_name ht2.example.net;
ssl_certificate /etc/letsencrypt/live/example.net/cert.pem;
ssl_certificate_key /etc/letsencrypt/live/example.net/privkey.pem
ssl_protocols TLSv1.3;
location / {
# Proxy to the appropriate backend based on the client's IP version
proxy_pass http://$backend_ht2;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
I want that the reverse proxy proxies both the ipv4 and ipv6 addresses of my server… but the test:
nginx -t
throws me the error:
nginx: [emerg] "upstream" directive is not allowed here in /etc/nginx/sites-enabled/example.conf:2
nginx: configuration file /etc/nginx/sites-enabled/example_config.conf test failed
Please help… Thank you :'|
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Enter your email to get $200 in credit for your first 60 days with DigitalOcean.
New accounts only. By submitting your email you agree to our Privacy Policy.
Heya,
Try with the following Nginx config: