Whats wrong with this config?

I created this nginx config(using my own domain not example) and restarted nginx but when I went to the website it still directs me to the local server rather than the "remote" server I want it to
server {
listen 80;
server_name example.com;

location / {
proxy_pass http://other-server;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
server {
listen 80;
server_name example.com;

location / {
proxy_pass http://other-server;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
25 Replies
Admincraft Meta
Thanks for asking your question!
Make sure to provide as much helpful information as possible such as logs/what you tried and what your exact issue is
Make sure to mark solved when issue is solved!!!
/close !close !solved !answered
Requested by lavaking46#0
luketeam5
luketeam52y ago
Where is the config placed? If in sites-available did you create a symbolic link?
lavaking46
lavaking46OP2y ago
yes ^
Philipp
Philipp2y ago
Is there a other config that overrides this one
QarthO
QarthO2y ago
when you go to your domain, are you using http, or https?
luketeam5
luketeam52y ago
Hm, try nginx -t to test the configs. Wait, doesn't proxypass require a IP adress not a domain? Also, what are you trying to do if I can ask?
lavaking46
lavaking46OP2y ago
I tried with both http and https To reply to all three of your questions: 1. I tested that and it says everything is good 2. I have no idea. I give it an ip-address I just put a placeholder there so as not to reveal that information 3. I have two physical servers in my network. I can only port forward to one of them because of my router. one of the servers needs to be the one port forwarded to but I still want to access what I am hosting on the other server
luketeam5
luketeam52y ago
If they are on the same network shouldn't you port forward it to local network instead of public IP? I have my portforwarding set up like this and it runs without any issues.
server {
server_name dynmap.luketeam5.xyz;
listen 443;
ssl_certificate ...
ssl_certificate_key ...

location / {
proxy_pass http://10.0.0.240:2082/;
# 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-Host $server_name;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_http_version 1.1;
}
}
server {
server_name dynmap.luketeam5.xyz;
listen 443;
ssl_certificate ...
ssl_certificate_key ...

location / {
proxy_pass http://10.0.0.240:2082/;
# 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-Host $server_name;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_http_version 1.1;
}
}
Also, is the port open on the second server?
lavaking46
lavaking46OP2y ago
yes its not to a public IP its all internal I just didn't share said IP unrelated question. what is the x-forwarded-proto for?
luketeam5
luketeam52y ago
It passes the protocol (HTTP, HTTPS, ..) to the proxy. Oh, I was confused as I tought that you were using a public IP as there is no reason to censor localhost.
lavaking46
lavaking46OP2y ago
yeah I don't know why I thought I should censor it
luketeam5
luketeam52y ago
Anyways, couple more ideas and then I have no clue what is wrong. 1. Any errors in the error log? 2. Try incognito mode, sometimes browser directly (skip the request entirely) redirect you to the wrong adress. 3. Try pinging the local address 4. Check once again for configuration conflicts (mainly default in nginx/sites-enabled, and check nginx/conf.d
lavaking46
lavaking46OP2y ago
I can connect to the local IP directly. the default config is disabled. I have another config but its set for a different domain entirely. SSL error 2023/08/09 09:39:57 [error] 1259345#1259345: *4 SSL_do_handshake() failed (SSL: error:0A00010B:SSL routines::wrong version number) while SSL handshaking to upstream, client: IP, server: lavaking46.com, request: "GET / HTTP/1.1", upstream: "https://10.0.0.86:80/", host: "IP"
luketeam5
luketeam52y ago
Connecting is not the same as pinging it as it might have some issues with that specific machine. According to the error you are using https (443) while listening for http (80).
lavaking46
lavaking46OP2y ago
I tried connecting to the server with port 443 and it throws a bad request error. switching my connection to http doesnt change anything
luketeam5
luketeam52y ago
You said that you are running it locally, is it possible that the router is blocking the traffic and thus causing the "wrong version number" error?
lavaking46
lavaking46OP2y ago
router isn't blocking it. I just checked the logs trying in incognito does the same thing. it can ping the machine just fine. also the error occured earlier but no longer occurs
luketeam5
luketeam52y ago
Alright, I have no clue what is wrong then, sorry.
Discount Milk
Discount Milk2y ago
Wym by "you can only port forward to one"? Wait you're not the one using DMZ as "port forwarding", are you?
lavaking46
lavaking46OP2y ago
I have learned a lot of things about port forwarding. I hadn't entirely realized til now(it just didn't come to mind) that port forwarding has to assign each port to a specific internal ip and port meaning port forwarding always directs to one internal machine I'm not using a DMZ no. I have been told to but I think its a bad idea
Discount Milk
Discount Milk2y ago
@lavaking46
lavaking46
lavaking46OP2y ago
the difference is the name of the domain + ip
Discount Milk
Discount Milk2y ago
It hid because no messages in a week
lavaking46
lavaking46OP2y ago
ah ok
server {
listen 80;
server_name .lavaking46.com;

location / {
proxy_bind $server_addr;
proxy_pass http://10.0.0.86;
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;
proxy_http_version 1.1;
}
}
server {
listen 80;
server_name .lavaking46.com;

location / {
proxy_bind $server_addr;
proxy_pass http://10.0.0.86;
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;
proxy_http_version 1.1;
}
}
config for the site nginx config:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
worker_connections 768;
# multi_accept on;
}

http {

##
# Basic Settings
##

sendfile on;
tcp_nopush on;
types_hash_max_size 2048;
# server_tokens off;

# server_names_hash_bucket_size 64;
# server_name_in_redirect off;

include /etc/nginx/mime.types;
default_type application/octet-stream;

##
# SSL Settings
##

ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;

##
# Logging Settings
##

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

##
# Gzip Settings
##

gzip on;

# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

##
# Virtual Host Configs
##

include /etc/nginx/conf.d/*.conf;
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
worker_connections 768;
# multi_accept on;
}

http {

##
# Basic Settings
##

sendfile on;
tcp_nopush on;
types_hash_max_size 2048;
# server_tokens off;

# server_names_hash_bucket_size 64;
# server_name_in_redirect off;

include /etc/nginx/mime.types;
default_type application/octet-stream;

##
# SSL Settings
##

ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;

##
# Logging Settings
##

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

##
# Gzip Settings
##

gzip on;

# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

##
# Virtual Host Configs
##

include /etc/nginx/conf.d/*.conf;
!close
Admincraft Meta
post closed!
The post/thread has been closed!
Requested by lavaking46#0

Did you find this page helpful?