LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 12-29-2017, 06:48 PM   #1
chripy811
LQ Newbie
 
Registered: Mar 2017
Posts: 20

Rep: Reputation: Disabled
reverse proxy nginx, what's wrong with my setup


hello! i'm trying to setup a reverse proxy on my server, but i can't seem to get it working,


this is my config file in /usr/share/nginx/modules/website.conf

Code:
server {
listen 80;
listen [::]80;
server_name example.com;
#root /usr/share/nginx/html;

location / {
proxy_pass "http://192.168.1.102";
}
error_page 404 /404.html;
location =/40x.html{
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
when i put example.com in the browser all i see is the nginx website


this my windows machine, and setup
Attached Thumbnails
Click image for larger version

Name:	windows.png
Views:	13
Size:	96.7 KB
ID:	26628   Click image for larger version

Name:	reverse proxy.png
Views:	12
Size:	33.8 KB
ID:	26630  

Last edited by chripy811; 12-29-2017 at 07:09 PM.
 
Old 12-30-2017, 02:40 AM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 12,270

Rep: Reputation: 1690Reputation: 1690Reputation: 1690Reputation: 1690Reputation: 1690Reputation: 1690Reputation: 1690Reputation: 1690Reputation: 1690Reputation: 1690Reputation: 1690
Quote:
this is my config file in /usr/share/nginx/modules/website.conf
This is not the default location for a nginx vhost config file. Are you sure nginx reads that file?
Also don't forget to restart nginx and clear your browser cache before testing.

Regards
 
Old 01-03-2018, 02:40 AM   #3
624867243@qq.com
Member
 
Registered: Nov 2015
Location: ShenZhen
Posts: 33
Blog Entries: 1

Rep: Reputation: Disabled
it may like this
Code:
server {
listen 80;
server_name example.com;
#root /usr/share/nginx/html;

     location ~ ^/ {
          proxy_pass http://192.168.1.102;
               }
          error_page 404 /404.html;
          location =/40x.html{
          }
         error_page 500 502 503 504 /50x.html;
       location = /50x.html {
     }
}
 
Old 01-03-2018, 02:19 PM   #4
chripy811
LQ Newbie
 
Registered: Mar 2017
Posts: 20

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by 624867243@qq.com View Post
it may like this
Code:
server {
listen 80;
server_name example.com;
#root /usr/share/nginx/html;

     location ~ ^/ {
          proxy_pass http://192.168.1.102;
               }
          error_page 404 /404.html;
          location =/40x.html{
          }
         error_page 500 502 503 504 /50x.html;
       location = /50x.html {
     }
}

this does not work, nginx won't start it says

"server" directive is not allowed here in /usr/share/nginx/modules/nano.conf:1
nginx: configuaration file /etc/nginx/nginx.conf test failed




Quote:
Originally Posted by bathory View Post
This is not the default location for a nginx vhost config file. Are you sure nginx reads that file?
Also don't forget to restart nginx and clear your browser cache before testing.

Regards
in my /etc/nginx/nginx/conf

it says include /usr/share/nginx/models/*.conf;
Attached Thumbnails
Click image for larger version

Name:	reverse.png
Views:	7
Size:	29.6 KB
ID:	26665  
 
Old 01-03-2018, 02:51 PM   #5
chripy811
LQ Newbie
 
Registered: Mar 2017
Posts: 20

Original Poster
Rep: Reputation: Disabled
here are my complete files


Code:
# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

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

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

# Settings for a TLS enabled server.
#
#    server {
#        listen       443 ssl http2 default_server;
#        listen       [::]:443 ssl http2 default_server;
#        server_name  _;
#        root         /usr/share/nginx/html;
#
#        ssl_certificate "/etc/pki/nginx/server.crt";
#        ssl_certificate_key "/etc/pki/nginx/private/server.key";
#        ssl_session_cache shared:SSL:1m;
#        ssl_session_timeout  10m;
#        ssl_ciphers HIGH:!aNULL:!MD5;
#        ssl_prefer_server_ciphers on;
#
#        # Load configuration files for the default server block.
#        include /etc/nginx/default.d/*.conf;
#
#        location / {
#        }
#
#        error_page 404 /404.html;
#            location = /40x.html {
#        }
#
#        error_page 500 502 503 504 /50x.html;
#            location = /50x.html {
#        }
#    }

}



Code:
server {
listen 80;
server_name example.com;
#root /usr/share/nginx/html;

	location ~ ^/ {
		proxy_pass http://192.168.1.102;
			}
		error_page 404 /404.html;
		location = /40x.html{
		}
		error_page 500 502 503 504 /50x.html;
	location = /50x.html {
	}
}
 
Old 01-03-2018, 03:14 PM   #6
vincix
Member
 
Registered: Feb 2011
Distribution: Centos 7
Posts: 907

Rep: Reputation: 74
What is the content of /usr/share/nginx/modules/nano.conf?

I also don't think you should add configuration files under /usr/share/nginx. I'd suggest using /etc/nginx. Under /usr/share/nginx/modules are only modules loading loaded with load_module directives. At least that's how it seems to be on Centos.
 
Old 01-03-2018, 06:15 PM   #7
chripy811
LQ Newbie
 
Registered: Mar 2017
Posts: 20

Original Poster
Rep: Reputation: Disabled
It is the configurations pointing to my server, i thought you had to add it on a separate file,
i didn't know you could put it in the same file, so i put it in that file and i got it working!

I ended up putting it all in the /etc/nginx/nginx.conf


heres how it looks

Code:
# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
   server {
    listen 80;
    server_name WIN-esdx1;
    location    /  {
        proxy_set_header     x-real-IP                $remote_addr;
        proxy_set_header     x-forwarded-for          $proxy_add_x_forwarded_for;
        proxy_set_header     host                     $host;
        proxy_pass           http://192.168.1.104;
    }
   
   }
   

   

}

this seems to be working!






now i am trying to get 2 servers working, but it doesn't seem to be working,
i will continue to see if i can get it working




Code:
# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
   server {
    listen 80;
    server_name WIN-esdx1;
    location    /  {
        proxy_set_header     x-real-IP                $remote_addr;
        proxy_set_header     x-forwarded-for          $proxy_add_x_forwarded_for;
        proxy_set_header     host                     $host;
        proxy_pass           http://192.168.1.104;
    }
   
   }
   
   
     server {
    listen 80;
    server_name WIN-esdx2;
    location    /  {
        proxy_set_header     x-real-IP                $remote_addr;
        proxy_set_header     x-forwarded-for          $proxy_add_x_forwarded_for;
        proxy_set_header     host                     $host;
        proxy_pass           http://192.168.1.109;
    }
   
   } 
   

}
 
Old 01-04-2018, 01:08 PM   #8
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 12,270

Rep: Reputation: 1690Reputation: 1690Reputation: 1690Reputation: 1690Reputation: 1690Reputation: 1690Reputation: 1690Reputation: 1690Reputation: 1690Reputation: 1690Reputation: 1690
Quote:
now i am trying to get 2 servers working, but it doesn't seem to be working,
i will continue to see if i can get it working
What exactly is the problem you're facing?
Some logs could be helpful here.
 
Old 01-04-2018, 05:07 PM   #9
chripy811
LQ Newbie
 
Registered: Mar 2017
Posts: 20

Original Poster
Rep: Reputation: Disabled
I have 1 server, and on that server i have 3 virtual machines, i have 1 ip, server is using esxi

vm1 -centOS - reverse proxy
vm2 -WindowsServer - website 1
vm3 -WindowsServer - website 2

reverse proxy is half working
I can access website 1,
but website2 is not working, i get a Not Found HTTP Error 404. The requested resource is not found.
even if i turn off vm3, it still says not found, i think its going to vm2 and not vm3


theres something in my nginx.conf file thats not right

it works for 1 server, but as soon as i put 2 servers in that file, 1 doesn't work

Last edited by chripy811; 01-04-2018 at 05:54 PM.
 
Old 01-05-2018, 03:01 AM   #10
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 12,270

Rep: Reputation: 1690Reputation: 1690Reputation: 1690Reputation: 1690Reputation: 1690Reputation: 1690Reputation: 1690Reputation: 1690Reputation: 1690Reputation: 1690Reputation: 1690
Quote:
I can access website 1,
but website2 is not working, i get a Not Found HTTP Error 404. The requested resource is not found.
even if i turn off vm3, it still says not found, i think its going to vm2 and not vm3
I guess you mean that when you stop vm2 you get the 404 error. What is this error about? What's in the logs?

Anyway your config looks good, so it should work. Are you sure you're restarting nginx and cleaning your browser cache?
 
Old 01-05-2018, 07:02 AM   #11
chripy811
LQ Newbie
 
Registered: Mar 2017
Posts: 20

Original Poster
Rep: Reputation: Disabled
I don't mean that. Heres what i mean when i tested

nginx running
vm1 website 1 - working
vm2 website 2 - error 404


if i turn off vm2 (what is supposed to happen is vm2 shouldn't even say 404, the domain should give me a connection timed out)
nginx running
vm1 website 1 - working
vm2(turned off) website 2 - error 404


if i turned off vm1
nginx running
vm1 (turned off)website 1 - connection timed out
vm2 website 2 - connection timed out



i even tried flipping around the vm's because i thought it might be a vm2 problem, but it's not, vm2 works fine alone,
I even tried setting up another linux machine with a website, because i thought maybe it was 2 windows machines having conflict but same problem,


the second domain is not actually going to the second vm, thats why it still says 404 when i turned it off, because the 404 is coming from the first vm,

i cleared my cookies and cache, and nothing

where can i find the logs? on which vm should i be looking?
i doubt that there would be any logs on vm2 since the domain is not even hitting it

so either centos or vm1?
i checked /c:/inetpub/logs but nothing

where exactly do i check for centos
 
Old 01-05-2018, 08:06 AM   #12
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 12,270

Rep: Reputation: 1690Reputation: 1690Reputation: 1690Reputation: 1690Reputation: 1690Reputation: 1690Reputation: 1690Reputation: 1690Reputation: 1690Reputation: 1690Reputation: 1690
Quote:
nginx running
vm1 website 1 - working
vm2 website 2 - error 404

if i turn off vm2 (what is supposed to happen is vm2 shouldn't even say 404, the domain should give me a connection timed out)
nginx running
vm1 website 1 - working
vm2(turned off) website 2 - error 404

if i turned off vm1
nginx running
vm1 (turned off)website 1 - connection timed out
vm2 website 2 - connection timed out

i even tried flipping around the vm's because i thought it might be a vm2 problem, but it's not, vm2 works fine alone,
To me it looks like nginx is aware only for one vhost. Are you sure it reads the correct config file( the one with the 2 vhosts)?
You can run the following to list the vhosts:
Code:
find /etc/nginx/ -type f -name "*.conf" -print0 | xargs -0 egrep '^(\s|\t)*server_name'

Quote:
where can i find the logs? on which vm should i be looking?
i doubt that there would be any logs on vm2 since the domain is not even hitting it

so either centos or vm1?
i checked /c:/inetpub/logs but nothing
Dunno anything about windows, but according to this it should be at %SystemDrive%\inetpub\LogFiles (or %SystemDrive%\inetpub\logs\LogFiles).
Perhaps you may need to activate logging first.

Last edited by bathory; 01-05-2018 at 04:11 PM.
 
Old 01-05-2018, 03:52 PM   #13
chripy811
LQ Newbie
 
Registered: Mar 2017
Posts: 20

Original Poster
Rep: Reputation: Disabled
I checked the windows logs, and it is enabled, but there is just an empty file,

as for CentOs, I typed what you told me but nothing happened
i tried it with an ip instead of server name, but same thing happened, just went back to the #
as the picture below
i also think nginx only sees 1 host
Attached Thumbnails
Click image for larger version

Name:	cmd.png
Views:	9
Size:	2.1 KB
ID:	26679  

Last edited by chripy811; 01-05-2018 at 03:54 PM.
 
Old 01-05-2018, 04:35 PM   #14
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 12,270

Rep: Reputation: 1690Reputation: 1690Reputation: 1690Reputation: 1690Reputation: 1690Reputation: 1690Reputation: 1690Reputation: 1690Reputation: 1690Reputation: 1690Reputation: 1690
Quote:
I typed what you told me but nothing happened
You're not supposed to replace server_name with the actual name of the vhost in the command, as I see in the screenshot.
Running the command as-is should show the "server_name" directives that exist in the config file(s) under /etc/nginx/, so we could see what vhosts are defined.

If you ran the command (even using the vhost name WIN-N...) and got nothing, that means that nginx reads the wrong configuration. Maybe it still uses the config file from /usr/share/nginx/modules/ as in your OP.
 
Old 01-05-2018, 06:11 PM   #15
chripy811
LQ Newbie
 
Registered: Mar 2017
Posts: 20

Original Poster
Rep: Reputation: Disabled
oh i see!

I left it as is and nginx shows both servers. This is what it shows

Code:
/etc/nginx/nginx.conf:   server_name WIN-NCS099AKERA;
/etc/nginx/nginx.conf:   server_name WIN-S2;

those are correct, i looked inside my windows vm, and it matches with the server name
i also deleted the before config in modules, and i installed a new centos vm also,
just in case the old vm was corrupt, but nothing

Last edited by chripy811; 01-05-2018 at 06:13 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Nginx Reverse Proxy Sut Ram Linux - Server 3 08-29-2016 06:55 AM
Nginx reverse proxy szemy Linux - Server 1 01-22-2016 02:59 AM
LXer: Install GlassFish 4.1 and setup reverse proxy with Nginx on an Ubuntu 14.04 VPS LXer Syndicated Linux News 0 06-03-2015 02:12 AM
Nginx Reverse proxy on a internal apache reverse server ITiger Linux - Software 0 04-25-2014 07:44 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 05:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration