# Configuration problem with subdomain and proxy\_pass

**URL:** <https://www.ruby-forum.com/t/configuration-problem-with-subdomain-and-proxy-pass/214153>\
**Category:** NGINX\
**Created:** [November 23, 2011, 12:23pm UTC](https://www.ruby-forum.com/t/configuration-problem-with-subdomain-and-proxy-pass/214153 "2011-11-23T12:23:00Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [November 23, 2011, 12:23pm UTC](https://www.ruby-forum.com/t/configuration-problem-with-subdomain-and-proxy-pass/214153/1 "2011-11-23T12:23:00Z")

</div>

Hi,

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

[mydomain.com](http://mydomain.com) (port 80) → [http://localhost:8080/](http://localhost:8080/)  
[www.mydomain.com](http://www.mydomain.com) (port 80) → [http://localhost:8080/](http://localhost:8080/)  
[subdomain.mydomain.com](http://subdomain.mydomain.com) (port 80) → [http://localhost:8080/subdomain](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](http://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](http://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](http://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](http://subdomain.mydomain.com) doesn’t work (there is no  
response from server).

Oh, and [http://mydomain.com/subdomain](http://mydomain.com/subdomain) in browser works well too.

I will be grateful for your help.

Posted at Nginx Forum:

> **[configuration problem with subdomain and proxy\_pass](https://forum.nginx.org/read.php?2,218793,218793#msg-218793)**
>
> 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) --\>...

---

<div class="post-metadata">

**Author:** ![nicksoft](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/22d042/32.png) [@nicksoft](https://www.ruby-forum.com/u/nicksoft)\
**Post date:** [November 23, 2011, 1:32pm UTC](https://www.ruby-forum.com/t/configuration-problem-with-subdomain-and-proxy-pass/214153/2 "2011-11-23T13:32:22Z")

</div>

Hi,

Small observation, from your configuration

[http://subdomain.mydomain.com](http://subdomain.mydomain.com)

Will initiate a request to

[http://localhost:8080/subdomain/](http://localhost:8080/subdomain/)

and not

[http://localhost:8080/subdomain](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.

---

<div class="post-metadata">

**Author:** ![nicksoft](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/22d042/32.png) [@nicksoft](https://www.ruby-forum.com/u/nicksoft)\
**Post date:** [November 23, 2011, 3:27pm UTC](https://www.ruby-forum.com/t/configuration-problem-with-subdomain-and-proxy-pass/214153/3 "2011-11-23T15:27:06Z")

</div>

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](http://subdomain.mydomain.com), request: “GET / HTTP/1.1”, upstream:  
“[http://127.0.0.1:8080/subdomain/](http://127.0.0.1:8080/subdomain/)”, host: “[subdomain.mydomain.com](http://subdomain.mydomain.com)”

Posted at Nginx Forum:

> **[Re: configuration problem with subdomain and proxy\_pass](https://forum.nginx.org/read.php?2,218793,218839#msg-218839)**
>
> 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) --\>...

---

<div class="post-metadata">

**Author:** ![nicksoft](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/22d042/32.png) [@nicksoft](https://www.ruby-forum.com/u/nicksoft)\
**Post date:** [November 23, 2011, 2:59pm UTC](https://www.ruby-forum.com/t/configuration-problem-with-subdomain-and-proxy-pass/214153/4 "2011-11-23T14:59:48Z")

</div>

@faskiri.devel

[http://localhost:8080/subdomain/](http://localhost:8080/subdomain/)  
is equals to  
[http://localhost:8080/subdomain](http://localhost:8080/subdomain)

Both work the same.

In DNS control Panel of my domain I have a ‘A record’ :  
[subdomain.mydomain.com](http://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:

> **[Re: configuration problem with subdomain and proxy\_pass](https://forum.nginx.org/read.php?2,218793,218827#msg-218827)**
>
> 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) --\>...

---

<div class="post-metadata">

**Author:** ![nicksoft](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/22d042/32.png) [@nicksoft](https://www.ruby-forum.com/u/nicksoft)\
**Post date:** [November 23, 2011, 6:09pm UTC](https://www.ruby-forum.com/t/configuration-problem-with-subdomain-and-proxy-pass/214153/5 "2011-11-23T18:09:30Z")

</div>

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

wget [http://127.0.0.1:8080/subdomain/](http://127.0.0.1:8080/subdomain/) --header “host:  
[subdomain.mydomain.com](http://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/](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](http://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:

> **[Re: configuration problem with subdomain and proxy\_pass](https://forum.nginx.org/read.php?2,218793,218867#msg-218867)**
>
> 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) --\>...

---

<div class="post-metadata">

**Author:** ![nicksoft](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/22d042/32.png) [@nicksoft](https://www.ruby-forum.com/u/nicksoft)\
**Post date:** [November 23, 2011, 6:10pm UTC](https://www.ruby-forum.com/t/configuration-problem-with-subdomain-and-proxy-pass/214153/6 "2011-11-23T18:10:45Z")

</div>

For: wget [http://127.0.0.1:8080/subdomain/](http://127.0.0.1:8080/subdomain/) otuput:

–2011-11-23 17:09:10-- [http://127.0.0.1:8080/subdomain/](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:

> **[Re: configuration problem with subdomain and proxy\_pass](https://forum.nginx.org/read.php?2,218793,218869#msg-218869)**
>
> 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) --\>...

---

<div class="post-metadata">

**Author:** ![nicksoft](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/22d042/32.png) [@nicksoft](https://www.ruby-forum.com/u/nicksoft)\
**Post date:** [November 23, 2011, 6:18pm UTC](https://www.ruby-forum.com/t/configuration-problem-with-subdomain-and-proxy-pass/214153/7 "2011-11-23T18:18:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![nicksoft](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/22d042/32.png) [@nicksoft](https://www.ruby-forum.com/u/nicksoft)\
**Post date:** [November 23, 2011, 7:18pm UTC](https://www.ruby-forum.com/t/configuration-problem-with-subdomain-and-proxy-pass/214153/8 "2011-11-23T19:18:48Z")

</div>

Thank you. I will check tomcat configuration.

Posted at Nginx Forum:

> **[Re: configuration problem with subdomain and proxy\_pass](https://forum.nginx.org/read.php?2,218793,218875#msg-218875)**
>
> 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) --\>...

---

<div class="post-metadata">

**Author:** ![nicksoft](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/22d042/32.png) [@nicksoft](https://www.ruby-forum.com/u/nicksoft)\
**Post date:** [November 23, 2011, 5:09pm UTC](https://www.ruby-forum.com/t/configuration-problem-with-subdomain-and-proxy-pass/214153/9 "2011-11-23T17:09:57Z")

</div>

Can you try:

curl [http://127.0.0.1:8080/subdomain/](http://127.0.0.1:8080/subdomain/) -H “host: [subdomain.mydomain.com](http://subdomain.mydomain.com)”  
-v

or

wget [http://127.0.0.1:8080/subdomain/](http://127.0.0.1:8080/subdomain/) --header “host:  
[subdomain.mydomain.com](http://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 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> * * *
> 
> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](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_
