Welcome! Log In Create A New Profile

Advanced

need some help settign up nginx as a proxy to apache2

Posted by ovidiu 
need some help settign up nginx as a proxy to apache2
November 02, 2010 07:09AM
I am trying to follow this how-to from howtoforge.com: http://www.howtoforge.com/nginx-catch-all-host-as-front-end-to-apache-for-ispconfig-3-on-debian-lenny

I am running latest Debian with nginx from backports version 0.7.67 and currently nginx is on port 82 and Apache2 on 80 until I finish testing.

Using the tutorial as is results in the following errors for me: [code]
2010/10/23 04:20:05 [error] 28148#0: *7 localhost could not be resolved (5: Operation refused), client: 127.0.0.1, server: _, request: "GET /server-status?auto HTTP/1.1", host: "localhost"
[/code]

I had to make some changes to it and am not sure about those. With these changes I get past above mentioned error:

I changed this: [code]
RPAFsethostname On
RPAFproxy_ips 127.0.0.1 YOU_IP_ADDRESS
[/code] into this [code]
RPAFenable On
RPAFsethostname On
RPAFproxy_ips 127.0.0.1 YOU_IP_ADDRESS
[/code]

and changed these lines inside: /etc/nginx/sites-available/default
[code]

listen 80 default;
[/code]
into [code]
listen my_IP:80 default;
[/code]

and [code]
proxy_pass http://$host:82;
[/code]
into [code]
proxy_pass http://my_IP:82;
[/code] and I commented this completely as I don't want to override user's preferences for www vs non-www: [code]
#### www. redirect - all domains starting with www will be redirected to http://domain. ####
if ($host ~* ^(www\.)(.+)) {
set $rawdomain $2;
rewrite ^/(.*)$ http://$rawdomain/$1 permanent;
}

[/code]


this made it work. partially. what I am getting now are the following errors, maybe you can help shed some light onto them:

[code]
2010/11/02 11:54:26 [error] 23886#0: *1 open() "/var/www/ssali.zice.ro/web/wp-includes/images/adminbar.png" failed (2: No such file or directory), client: 196.215.110.94, server: _, request: "GET /wp-includes/images/adminbar.png HTTP/1.1", host: "ssali.zice.ro:82", referrer: "http://ssali.zice.ro:82/"
[/code]
this one zice.ro is a domain running wordpress multi-user that means anyone can register for a subdomain. obviously only the folder /var/ww/zice.ro exists and none of the virtually handled sub folders. how do I get nginx now to only look for the main domain and not for the sub domain?

I am also getting a couple of these: [code]
2010/11/01 23:19:39 [error] 22404#0: *3 connect() failed (111: Connection refused) while connecting to upstream, client: 196.215.52.247, server: _, request: "GET /wp-content/plugins/wp-wall/wp-wall-ajax.php?refresh=1 HTTP/1.1", upstream: "http://127.0.0.1:82/wp-content/plugins/wp-wall/wp-wall-ajax.php?refresh=1", host: "pacura.ru", referrer: "http://pacura.ru/pictures/2010/safari-through-namibia-botswana-and-zimbabwe/"
[/code]
not sure where the connection to http://127.0.0.1:82 comes from? (yes I exchanged nginx and apache roles for a few minutes to do some live testing and it failed, that is why the IPs are reversed here..

also getting these: [code]
2010/11/01 23:14:47 [error] 22404#0: *72 open() "/var/www/www.021club.co.za/web/wp-content/plugins/mailpress/mp-includes/images/loading.gif" failed (2: No such file or directory), client: 196.215.52.247, server: _, request: "GET /wp-content/plugins/mailpress/mp-includes/images/loading.gif HTTP/1.1", host: "www.021club.co.za", referrer: "http://www.021club.co.za/" the problem here is that the folder www.021club.co.za doesn't exist. it exists only without the www
[/code]

I'd appreciate any pointers on how to fix these probs. Really need to get some strain off my apache server :-(
Re: need some help settign up nginx as a proxy to apache2
November 03, 2010 12:52PM
meanwhile I found this configuration example: http://wiki.nginx.org/VirtualHostExample#Wildcard_Subdomains_in_a_Parent_Folder

which should solve my wildcard subdomain problem but that means I need to solve the problem: [code]
2010/10/23 04:20:05 [error] 28148#0: *7 localhost could not be resolved (5: Operation refused), client: 127.0.0.1, server: _, request: "GET /server-status?auto HTTP/1.1", host: "localhost"
[/code]

server: _; and $host can't be resolved.
here is my config: [code]
cat /etc/resolv.conf
# Generated by dhcpcd for interface eth0
search stratoserver.net
nameserver 85.214.7.22
nameserver 81.169.163.106
nameserver 81.169.148.34
[/code]
[code]
cat /etc/hosts
127.0.0.1 localhost
85.214.146.68 h1550830.stratoserver.net h1550830
[/code]

so I see no reason why it won't resolve :-(
Re: need some help settign up nginx as a proxy to apache2
November 03, 2010 01:08PM
oh and here is my: /etc/apache2/mods-enabled/status.conf
[code]
<IfModule mod_status.c>
#
# Allow server status reports generated by mod_status,
# with the URL of http://servername/server-status
# Uncomment and change the ".example.com" to allow
# access from other hosts.
#
ExtendedStatus On
<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from localhost ip6-localhost 127.0.0.1
</Location>
</IfModule>
[/code]
Re: need some help settign up nginx as a proxy to apache2
November 03, 2010 01:49PM
made some more progress with the help of some guys on irv it seems these lines work:

[code]
listen 80 default;
proxy_pass http://127.0.0.1:82;
[/code]

as 127.0.0.1 is enough, no need to use $host there as this is a reverse proxy, nginx and apache2 are on the same box.

and another suggestion to solve the www vs non-www problem was something like this:

[code]
set $site_dir $host; if ($host ~ ^www\.(.*)) { set $site_dir $1; } root /var/www/$site_dir/web;
[/code]

will give that a try...
Re: need some help settign up nginx as a proxy to apache2
November 03, 2010 02:21PM
ok,that worked. the last step is to get an exception worked into the config file for domains that use wordpress with multisite enabled where wildcard subdomains are used.

the errors look like:

[QUOTE]2010/11/03 19:17:28 [error] 32439#0: *3 open() "/var/www/adi.zice.ro/web/wp-includes/images/adminbar.png" failed (2: No such file or directory), client: 196.210.184.232, server: _, request: "GET /wp-includes/images/adminbar.png HTTP/1.1", host: "adi.zice.ro:82", referrer: "http://adi.zice.ro:82/"
[/QUOTE]

the problem is nginx is looking for /var/www/adi.zice.ro/web/ which does nto exist. adi.zice.ro is a virtual subdomain handled by wordpress.

so basically I need to extend this: [QUOTE]set $site_dir $host; if ($host ~ ^www\.(.*)) { set $site_dir $1; } root /var/www/$site_dir/web; [/QUOTE] so that if $host is stripped of www and any subdomains these rewrite rules are executed: [QUOTE]rewrite ^.*/files/(.*) /wp-content/blogs.php?file=$1;
if (!-e $request_filename) {
rewrite ^.+?(/wp-.*) $1 last;
rewrite ^.+?(/.*\.php)$ $1 last;
rewrite ^ /index.php last;
}
[/QUOTE]

any help out there?
Re: need some help settign up nginx as a proxy to apache2
November 05, 2010 07:20AM
solved it mostly. still fighting minor problems. if anyone hits the same probs, contact me, willing to help.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 226
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready