Welcome! Log In Create A New Profile

Advanced

Using nginx as reverse proxy over Apache

Posted by xtester 
Using nginx as reverse proxy over Apache
November 15, 2010 09:16AM
Hi,
I am trying to install Nginx as simple reverse proxy over Apache so it would serve static files and proxy everything else to Apache. Apache is running on port 8000.
Both Nginx and Apache start up without any errors.

The problem is that no matter what i do i see default Apache page (like this http://mirror.centos.org/mirrorscripts/noindex_new.html) I don't understand why this is happening (Nginx config contains path to folders that do not contain this files)

I keep getting the following errors in error.log:
[error] 16144#0: *286 connect() failed (111: Connection refused) while connecting to upstream, client: x.x.x.x, server: www.mysite.com, request: "GET /dir/test.html HTTP/1.0", upstream: "http://127.0.0.1:8000/dir/test.html", host: "www.mysite.com"

Below is my Nginx config:

[size=small]user nginx nginx;
worker_processes 4;

error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

pid logs/nginx.pid;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;

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 logs/access.log main;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

gzip on;
gzip_min_length 500;
gzip_http_version 1.1;
gzip_proxied any;
gzip_comp_level 5;
gzip_types text/plain text/css
application/x-javascript text/xml
application/xml application/xml+rss
text/javascript image/x-icon;

server {
listen 80;
server_name mysite.com www.mysite.com;
access_log logs/host.access.log main;

# serve static files
location ~ ^/(images|javascript|js|css|flash|media|static)/ {
root /var/www/vhosts/mysite.com/httpdocs;
expires 30d;
}

# pass requests for dynamic content to rails/turbogears/zope, et al
location / {
proxy_pass http://127.0.0.1:8000;
}
}
}[/size]

Could you please tell what might be the problem ?
Nginx is run as "nginx" user under group "nginx" while while virtualhost root folder belongs to another user from another group. Could this be the problem ?
Re: Using nginx as reverse proxy over Apache
November 25, 2010 02:14PM
I have the same problem, did you solve it?
Re: Using nginx as reverse proxy over Apache
November 26, 2010 05:18AM
yes, i did
the problem was in apache and nginx configs - in one place i had "localhost" written, in other "127.0.0.1" and that was causing apache to work improperly

so you should carefully check apache and nginx configs once again
Re: Using nginx as reverse proxy over Apache
June 14, 2011 10:48AM
Sorry for arriving so late to this post, but right now I am having right the same annoying trouble and I did not quite understand your solution.
I mean, I've greped localhost and 127.0.0.1 all thru my apache.conf and my nginx.conf as well as thru my apache2|nginx/sites-availables/* and do not find any active line with such difference.
What files did you find that difference in ?

Thanks in advance.
Re: Using nginx as reverse proxy over Apache
June 16, 2011 02:50AM
Well ....something else I can say is, in my case I do not think that localhost != 127.0.0.1 is the mistake because in my case common request work but 1 among 50 or so they fail.
Re: Using nginx as reverse proxy over Apache
June 23, 2011 11:48AM
No one wants me :(

Ok I'll add more info on this topic:
I have found that 111 connection refused it's not my only error between Apache and Nginx.Other errors like Timeouts and others related to buffering troubles reading/writing upstreams also arise. Result of all of them is my website sometimes shows blank pages.
I suspect it is related to Apache not being able to serve contents to Nginx at speed this is requesting. However, I've enabled buffering and tuned parameters related to buffering and cache in my /etc/nginx/sites-available/mysite.com ...... anyway such errors keep on arising: randomly (probably due to overload) my website shows blank pages. I haven't yet been able to relate such blank pages with nginx or apache errors .........any light on all this ? pleeeeeaseee (miserably begging)
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 290
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