Nginx SubDomain proxy

Mun

Never Forget
Okay, I am done digging the internet for tonight, but though I might ask and see if anyone might know how to do this.

Here is said page: http://stats.gaming-servers.net/hlstats.php

I want that page to appear here:

http://www.gaming-servers.net/stats/hlstats.php

However, I can't seem to get it to work.

Here is the config I have tried:

location /stats/ {

    proxy_pass http://stats.gaming-servers.net/;

}

Though it maybe very simple, I have also tried many other tangents and I can't seem to get it to work. Im guessing the way I am trying to do it is illogical and there is a better solution unseen to me.

Mun
 

Adduc

New Member
If hosted on the same server:

location ^~ /stats {
    proxy_set_header Host stats.gaming-servers.net;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_pass http://127.0.0.1$request_uri;
}
If not hosted on the same server, you'll need to make sure nginx is using a resolver, and then you can replace the 127.0.0.1 with stats.gaming-servers.net.

Side Note: Using ($) scheme caused entire post to be messed up. No scheme, no problem.
 
Last edited by a moderator:

Mun

Never Forget
If hosted on the same server:


location ^~ /stats {
    proxy_set_header Host stats.gaming-servers.net;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_pass http://127.0.0.1$request_uri;
}

If not hosted on the same server, you'll need to make sure nginx is using a resolver, and then you can replace the 127.0.0.1 with stats.gaming-servers.net.


Side Note: Using ($) scheme caused entire post to be messed up. No scheme, no problem.
I had this same schema roughly, but it still doesnt work. Here is a snippet of the request from my logs:



My IP - - [17/Jul/2013:06:12:59 -0700] "GET /stats/ HTTP/1.0" 404 570 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36"
Server IP - - [17/Jul/2013:06:12:59 -0700] "GET /stats/ HTTP/1.0" 404 570 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36"


As you can see the proxy is actually asking from the source the path that I have for the main request.

Mun
 

happel

New Member
location /stats/ {
proxy_pass http://stats.gaming-servers.net/;
proxy_set_header X-Real-IP $remote_addr;
}

qEA7dbT.png

Edit: pay attention to the trailing slashes of the location and proxy_pass line. Other causes of your problems could be other location/rewrite blocks. I.e. a location ~ \.php$ {} block would try to execute the hlstats.php file on the main server instead of requesting it through the proxy.
 
Last edited by a moderator:

Mun

Never Forget
location /stats/ {
proxy_pass http://stats.gaming-servers.net/;
proxy_set_header X-Real-IP $remote_addr;
}

qEA7dbT.png

Edit: pay attention to the trailing slashes of the location and proxy_pass line. Other causes of your problems could be other location/rewrite blocks. I.e. a location ~ \.php$ {} block would try to execute the hlstats.php file on the main server instead of requesting it through the proxy.
Ahh, I think you have it. Is there anyway to get around that?
 

manacit

New Member
Your issue is likely that nginx will choose the first regex match for the request inside your configuration file, and disregard anything else. Quick and dirty hack might be to just add the same location block inside your php block?
 

Mun

Never Forget
Your issue is likely that nginx will choose the first regex match for the request inside your configuration file, and disregard anything else. Quick and dirty hack might be to just add the same location block inside your php block?
The way I fixed it in this case was I move the location ^~ /stats above ~php block. Seems to work. Now its just figuring out if I can make the apps understand that I am proxying the request.
 
Top