Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Server Operation

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 24th February 2012, 09:31
bzzik bzzik is offline
Member
 
Join Date: Aug 2008
Posts: 67
Thanks: 1
Thanked 2 Times in 2 Posts
Question nginx redirects back to remote_addr IP

Hi ppl

I am trying to setup nginx 1.0.12 as a proxy for apache 2.2.15, but faced strange problem. And I cannot solve it for third day in a row
I have test site http://c-craft.info and have installed roundcube in /roundcube subdirectory. So here is the problem:

If you will try to open http://c-craft.info/roundcube you will get strange redirect back to your own IP address. So nginx tries to download static files from remote_addr. But if you will add trailing slash to uri http://c-craft.info/roundcube/ it will work.

Another example: try to open http://www.contra.lv - you also will get redirect back to your own IP address and again nginx tries to download static files from remote_addr.

Interesting thing is that connencting through apache works nice:
http://c-craft.info:9091/roundcube
http://contra.lv:9091

I really need your advice how to fix it, cause I am stuck

Here is my config files:

nginx.conf
Quote:
user nginx;
worker_processes 2;
pid /var/run/nginx.pid;

events {
worker_connections 2048;
use epoll;
}

http {
include /etc/nginx/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 /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

client_max_body_size 64m;
client_body_buffer_size 256k;

sendfile on;
tcp_nopush on;
tcp_nodelay on;

keepalive_timeout 65;

gzip on;
gzip_vary on;
gzip_comp_level 6;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_buffers 16 8k;
gzip_disable "MSIE [1-6].(?!.*SV1)";

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
sites-enabled/default
Quote:
server {
listen 80 default;
server_name _;
server_name_in_redirect off;
server_tokens off;
access_log /var/log/nginx/default.access.log;
error_log /var/log/nginx/default.error.log;

location / {
proxy_pass http://8*.***.**.**6:9091;
include /etc/nginx/proxy.conf;
}
}
sites-enabled/c-craft.info.conf
Quote:
server {
listen 80;
server_name www.c-craft.info c-craft.info;
server_name_in_redirect off;

access_log /var/log/nginx/c-craft.info_access_log;
error_log /var/log/nginx/c-craft.info_error_log;

location / {
proxy_pass http://8*.***.**.**6:9091;
include /etc/nginx/proxy.conf;
}

location ~* ^.+\.(jpe?g|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc |xls|exe|pdf|ppt|txt|tar|mp3)$ {
expires 30d;
root /home/c-craft/public_html;
}
}
sites-enabled/contra.lv.conf
Quote:
server {
listen 8*.***.**.**6:80;
server_name www.contra.lv contra.lv;
access_log /var/log/nginx/contra.lv_nginx_access_log;
error_log /var/log/nginx/contra.lv_nginx_error_log;

location / {
proxy_pass http://8*.***.**.**6:9091;
include /etc/nginx/proxy.conf;
}

location ~* ^.+\.(jpe?g|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc |xls|exe|pdf|ppt|txt|tar|mp3)$ {
expires 30d;
root /home/contra/public_html;
}
}
proxy.conf
Quote:
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;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 16k;
proxy_buffers 32 8k;
proxy_busy_buffers_size 64k;

In apache httpd.conf I have:
Quote:
Listen 9091
UseCanonicalName Off
Thank you in advance for any advice you have

Last edited by bzzik; 24th February 2012 at 09:35.
Reply With Quote
Sponsored Links
  #2  
Old 24th February 2012, 13:40
Carlinforge Carlinforge is offline
Junior Member
 
Join Date: Jan 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default is this now working?

i reviewed the post and hello from c-craft.info does not redirect. Pls reply with an update as this is great way for newbie to learn ... thx in advance

Reply With Quote
  #3  
Old 24th February 2012, 16:23
bzzik bzzik is offline
Member
 
Join Date: Aug 2008
Posts: 67
Thanks: 1
Thanked 2 Times in 2 Posts
Default

Quote:
Originally Posted by Carlinforge View Post
i reviewed the post and hello from c-craft.info does not redirect. Pls reply with an update as this is great way for newbie to learn ... thx in advance

Yeah, this one does not redirect.
But http://c-craft.info/roundcube and http://www.contra.lv does... And this driving me crazy.
Reply With Quote
  #4  
Old 25th February 2012, 12:06
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 41,701
Thanks: 1,900
Thanked 2,749 Times in 2,579 Posts
Default

Quote:
Originally Posted by bzzik View Post
Yeah, this one does not redirect.
But http://c-craft.info/roundcube
c-craft.info/roundcube is working for me as well, while contra.lv isn't.

The only difference in your vhosts that I see is server_name_in_redirect off;
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
  #5  
Old 26th February 2012, 15:10
bzzik bzzik is offline
Member
 
Join Date: Aug 2008
Posts: 67
Thanks: 1
Thanked 2 Times in 2 Posts
Default

Quote:
Originally Posted by falko View Post
c-craft.info/roundcube is working for me as well, while contra.lv isn't.

The only difference in your vhosts that I see is server_name_in_redirect off;
c-craft.info/roundcube - you do not have any redirects? Sure that it opens normally without trailing slash?

I put server_name_in_redirect off; to contra.lv.conf, but it did not help...


Update:
Ok, I think I found the problem. For some reason $_SERVER["HTTP_HOST"] is incorrect - it is getting equal to $remote_addr, but not always... this is weird. I am trying to understand how does this happen, is it nginx, apache or PHP problem?

Update 2:
So this sounds like nginx problem... you can check two test addresses: http://contra.lv/server.php and http://contra.lv:9091/server.php. You can see, that HTTP_POST is different on nginx and apache...

Last edited by bzzik; 26th February 2012 at 16:21. Reason: Update
Reply With Quote
  #6  
Old 26th February 2012, 21:21
bzzik bzzik is offline
Member
 
Join Date: Aug 2008
Posts: 67
Thanks: 1
Thanked 2 Times in 2 Posts
 
Default

I solved one of the problems. On another forum user adviced me to change $host to $http_host in the proxy.conf and add there new line:
Quote:
proxy_set_header X-Forwarded-Host $http_host;
$_SERVER["HTTP_HOST"] is correct now and contra.lv is working In fact after adding this line
Quote:
proxy_set_header X-Forwarded-Host $http_host;
everything it started to work. But in all tutorials about nginx as reverse_proxy there is nothing about this line...

And the problem with trailing slash still exists: http://c-craft.info/roundcube still redirects back to $remote_addr.

Last edited by bzzik; 26th February 2012 at 21:34.
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
nginx Segmentation fault Error,The Perfect Server - CentOS 6 With nginx [ISPConfig 3] alihan1988 HOWTO-Related Questions 0 2nd February 2012 18:07
ispconfig 3.0.3.1 with nginx - updates give "Error while sending INIT_DB packet" talkingnews General 3 20th December 2011 13:28
A Working Nginx Catchall with ISPConfig 3. renders Tips/Tricks/Mods 4 15th April 2011 22:53
Nginx and PHP and Fastcgi Paladinemishakal Installation/Configuration 1 4th January 2011 14:45
Nginx on Fedora 11 Nammut HOWTO-Related Questions 1 3rd October 2009 17:35


All times are GMT +2. The time now is 13:52.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.