Configuration problem with subdomain and proxy_pass

Hi,

I have a problem with configuration subdomains for nginx. I want to
configure domains:

mydomain.com (port 80) --> http://localhost:8080/
www.mydomain.com (port 80) --> http://localhost:8080/
subdomain.mydomain.com (port 80) --> http://localhost:8080/subdomain

Tomcat listening at 8080 port on localhost. I have application
‘subdomain’ in tomcat webapps folder.

This is my configuration file:

server
{
listen 80;
server_name mydomain.com;

   # Main location
   location /
   {
       proxy_pass         http://127.0.0.1:8080/;
       proxy_redirect     off;

       proxy_set_header   Host             $host;
       proxy_set_header   X-Real-IP        $remote_addr;
       proxy_set_header   X-Forwarded-For

$proxy_add_x_forwarded_for;

       client_max_body_size       52m;
       client_body_buffer_size    128k;

       proxy_connect_timeout      3600;
       proxy_send_timeout         3600;
       proxy_read_timeout         90;

       proxy_buffer_size          4k;
       proxy_buffers              4 32k;
       proxy_busy_buffers_size    64k;
       proxy_temp_file_write_size 64k;
       proxy_cache_valid 5m;
   }

}

server
{
listen 80;
server_name www.mydomain.com;

   # Main location
   location /
   {
       proxy_pass         http://127.0.0.1:8080/;
       proxy_redirect     off;

       proxy_set_header   Host             $host;
       proxy_set_header   X-Real-IP        $remote_addr;
       proxy_set_header   X-Forwarded-For

$proxy_add_x_forwarded_for;

       client_max_body_size       52m;
       client_body_buffer_size    128k;

       proxy_connect_timeout      3600;
       proxy_send_timeout         3600;
       proxy_read_timeout         90;

       proxy_buffer_size          4k;
       proxy_buffers              4 32k;
       proxy_busy_buffers_size    64k;
       proxy_temp_file_write_size 64k;
       proxy_cache_valid 5m;
   }

}

server
{
listen 80;
server_name subdomain.mydomain.com;

   # Main location
   location /
   {
       proxy_pass         http://127.0.0.1:8080/subdomain/;
       proxy_redirect     off;

       proxy_set_header   Host             $host;
       proxy_set_header   X-Real-IP        $remote_addr;
       proxy_set_header   X-Forwarded-For

$proxy_add_x_forwarded_for;

       client_max_body_size       52m;
       client_body_buffer_size    128k;

       proxy_connect_timeout      3600;
       proxy_send_timeout         3600;
       proxy_read_timeout         90;

       proxy_buffer_size          4k;
       proxy_buffers              4 32k;
       proxy_busy_buffers_size    64k;
       proxy_temp_file_write_size 64k;
       proxy_cache_valid 5m;
   }

}

For this configuration http:/www.mydomain.com and http:/mydomain.com
working very well, but subdomain.mydomain.com doesn’t work (there is no
response from server).

Oh, and http://mydomain.com/subdomain in browser works well too.

I will be grateful for your help.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,218793,218793#msg-218793

Hi,

Small observation, from your configuration

http://subdomain.mydomain.com

Will initiate a request to

http://localhost:8080/subdomain/

and not

http://localhost:8080/subdomain

[notice the /] which you said works in the browser. You might want to
check
that out.

Also, you can check out the tomcat’s access logs to see what request you
got.

I found error in nginx log:

2011/11/22 16:26:12 [error] 1423#0: *1 connect() failed (111: Connection
refused) while connecting to upstream, client: xxx.yyy.zzz.vvv, server:
subdomain.mydomain.com, request: “GET / HTTP/1.1”, upstream:
http://127.0.0.1:8080/subdomain/”, host: “subdomain.mydomain.com

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,218793,218839#msg-218839

@faskiri.devel

http://localhost:8080/subdomain/
is equals to
http://localhost:8080/subdomain

Both work the same.

In DNS control Panel of my domain I have a ‘A record’ :
subdomain.mydomain.com with IP adress of my VPS server (with nginx and
tomcat). It should works… I don’t know what is wrong in my
configuration.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,218793,218827#msg-218827

This is otput from console (Debian 6 min.):

wget http://127.0.0.1:8080/subdomain/ --header “host:
subdomain.mydomain.com” --debug

DEBUG output created by Wget 1.12 on linux-gnu.

–2011-11-23 17:04:15-- http://127.0.0.1:8080/subdomain/
Connecting to 127.0.0.1:8080… connected.
Created socket 3.
Releasing 0x08dfc180 (new refcount 0).
Deleting unused 0x08dfc180.

—request begin—
GET /jaspresso/ HTTP/1.0
User-Agent: Wget/1.12 (linux-gnu)
Accept: /
host: subdomain.mydomain.com
Connection: Keep-Alive

—request end—
HTTP request sent, awaiting response…
—response begin—
HTTP/1.1 400 Bad Request
Server: Apache-Coyote/1.1
Date: Wed, 23 Nov 2011 17:04:15 GMT
Connection: close

—response end—
400 Bad Request
Closed fd 3
2011-11-23 17:04:15 ERROR 400: Bad Request.

Strange… What could it be?

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,218793,218867#msg-218867

For: wget http://127.0.0.1:8080/subdomain/ otuput:

–2011-11-23 17:09:10-- http://127.0.0.1:8080/subdomain/
Connecting to 127.0.0.1:8080… connected.
HTTP request sent, awaiting response… 200 OK
Length: 4761 (4.6K) [text/html]
Saving to: `index.html’

100%[===========================================================================================>]
4,761 --.-K/s in 0s

2011-11-23 17:09:10 (413 MB/s) - `index.html’ saved [4761/4761]

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,218793,218869#msg-218869

Your Apache is not set correctly. Please make sure that the VirtualHost
is
setup correctly.
Basically normal wget is working but if you set the host: header apache
rejects the request.

I think you have explicity put a VirtualHost domain:8080

changing that to VirtualHost *:8080 should fix it. In any case, since
plain
wget also gives you errors, you are better off looking at Apache
logs/manual than in nginx.

Thank you. I will check tomcat configuration.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,218793,218875#msg-218875

Can you try:

curl http://127.0.0.1:8080/subdomain/ -H “host: subdomain.mydomain.com
-v

or

wget http://127.0.0.1:8080/subdomain/ --header “host:
subdomain.mydomain.com” --debug

from the nginx machine and send the output, looks like there is some
error
in the network configuration

+Fasih

On Wed, Nov 23, 2011 at 7:56 PM, nicksoft [email protected] wrote:


nginx mailing list
remove[email protected]
http://mailman.nginx.org/mailman/listinfo/nginx


+Fasih

Wisdom doesn’t automatically come with old age. Nothing does - except
wrinkles. It’s true, some wines improve with age. But only if the grapes
were good in the first place

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs