nginx + Apache + mod-rpaf = problems
I just installed nginx as Reverse Proxy for Apache. But since all IP show as 127.0.0.1 I installed mod-rpaf to Apache so it have normal IP in log. And here I found some strange error, on some pages I have strange redirect to local user ip. Et if I go to “site.com/forum” I send me to “localip/forum”. It strange because if I go to “site.com/forum/” it don’t redirect me, and even more it have some extra redirect on pages like “site.com/forums/search.php?do=getnew” it send to “localip/forums/search.php?searchid=70593”.
If I turnoff mod-rpaf, all starts work fine, but if I turn it I again have same problem. Any one know what case that problem here? Apache? Or maybe vBulletin?
I don’t have may “mod_rewrite” for “forums” in my “.htaccess” file.
11 Replies
`<ifmodule mod_rewrite.c="">RewriteEngine on
RewriteCond %{HTTP_HOST} ^site1\.com$ [NC]
RewriteRule ^(.*)$ http://www.site1.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^site2\.com$ [NC]
RewriteRule ^(.*)$ http://www.site1.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^site4\.com$ [NC]
RewriteRule ^(.*)$ http://www.site1.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^site3\.com$ [NC]
RewriteRule ^(.*)$ http://www.site1.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^www\.site2\.com$ [NC]
RewriteRule ^(.*)$ http://www.site1.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^www\.site3\.com$ [NC]
RewriteRule ^(.*)$ http://www.site1.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^www\.site4\.com$ [NC]
RewriteRule ^(.*)$ http://www.site1.com/$1 [L,R=301]
### BOOST START ###
AddDefaultCharset utf-8
<filesmatch "(\.html|\.xml|\.json)$"=""><ifmodule mod_headers.c="">Header set Expires "Sun, 19 Nov 1978 05:00:00 GMT"
Header set Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"</ifmodule></filesmatch>
<ifmodule mod_mime.c="">AddCharset utf-8 .html
AddCharset utf-8 .xml
AddCharset utf-8 .css
AddCharset utf-8 .js
AddCharset utf-8 .json</ifmodule>
<filesmatch "(\.html)$"="">ForceType text/html</filesmatch>
<filesmatch "(\.xml)$"="">ForceType text/xml</filesmatch>
<filesmatch "(\.json|\.js)$"="">ForceType text/javascript</filesmatch>
<filesmatch "(\.css)$"="">ForceType text/css</filesmatch>
# NORMAL - Cached css & js files
RewriteCond %{DOCUMENT_ROOT}/cache/perm/%{SERVER_NAME}%{REQUEST_URI}_\.css -s
RewriteRule .* cache/perm/%{SERVER_NAME}%{REQUEST_URI}_\.css [L,QSA,T=text/css]
RewriteCond %{DOCUMENT_ROOT}/cache/perm/%{SERVER_NAME}%{REQUEST_URI}_\.js -s
RewriteRule .* cache/perm/%{SERVER_NAME}%{REQUEST_URI}_\.js [L,QSA,T=text/javascript]
# Caching for anonymous users
# Skip boost IF not get request OR uri has wrong dir OR cookie is set OR request came from this server OR https request
RewriteCond %{REQUEST_METHOD} !^(GET|HEAD)$ [OR]
RewriteCond %{REQUEST_URI} (^/(admin|cache|misc|modules|sites|system|openid|themes|node/add))|(/(comment/reply|edit|user|user/(login|password|register))$) [OR]
RewriteCond %{HTTP_COOKIE} DRUPAL_UID [OR]
RewriteCond %{HTTP:Pragma} no-cache [OR]
RewriteCond %{HTTP:Cache-Control} no-cache [OR]
RewriteCond %{HTTPS} on
RewriteRule .* - [s]
# NORMAL
RewriteCond %{DOCUMENT_ROOT}/cache/normal/%{SERVER_NAME}%{REQUEST_URI}_%{QUERY_STRING}\.html -s
RewriteRule .* cache/normal/%{SERVER_NAME}%{REQUEST_URI}_%{QUERY_STRING}\.html [L,T=text/html]
RewriteCond %{DOCUMENT_ROOT}/cache/normal/%{SERVER_NAME}%{REQUEST_URI}_%{QUERY_STRING}\.xml -s
RewriteRule .* cache/normal/%{SERVER_NAME}%{REQUEST_URI}_%{QUERY_STRING}\.xml [L,T=text/xml]
RewriteCond %{DOCUMENT_ROOT}/cache/normal/%{SERVER_NAME}%{REQUEST_URI}_%{QUERY_STRING}\.json -s
RewriteRule .* cache/normal/%{SERVER_NAME}%{REQUEST_URI}_%{QUERY_STRING}\.json [L,T=text/javascript]
### BOOST END ###
# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
RedirectMatch ^/contribut-missing-images$ /forums/showthread.php?t=67
RedirectMatch ^/user/password$ /forums/login.php?do=lostpw
RedirectMatch ^/user/(.*)$ /profile.php
RedirectMatch ^/users/(.*)$ /profile.php
RedirectMatch ^/messages$ http://www.site1.com/forums/private.php
#
# Externally redirect direct client requests for "/index.htm" to "/" in
# canonical domain (This applies to /index pages in any directory)
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.htm\ HTTP/
RewriteRule ^(([^/]+/)*)index\.htm$ http://www.site1.com/$1 [R=301,L]
#
# Externally redirect to remove multiple contiguous slashes at beginning or end of URL
RewriteCond %{REQUEST_URI} ^//+(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^(.*/)/+$
RewriteRule / http://www.site1.com/%1 [R=301,L]
#
# Externally redirect to remove multiple contiguous slashes embedded in URL
RewriteCond %{REQUEST_URI} ^/([^/]+)//+(.*)$
RewriteRule // http://www.site1.com/%1/%2 [R=301,L]</ifmodule>` [/s]
Here my nginx config:
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
gzip on;
server {
listen 80;
server_name _;
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;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
root /usr/share/nginx/html;
index index.html index.htm index.php;
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy static
location ~* ^.+.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$ {
root /home/www/static/;
expires 7d; # caching, expire after 7 days
}
}
As soon as I enable mod-rpaf it change server_name in all PHP Variable from server name to user ip
So intend of having this without mod-rpaf:
HTTP_HOST www.site.com
SERVER_SIGNATURE
<address>Apache Server at www.site.com Port 80</address>
SERVER_SOFTWARE Apache
SERVER_NAME www.site.com
SERVER_ADDR 127.0.0.1
SERVER_PORT 80
REMOTE_ADDR 127.0.0.1
With mod-rpaf I have this:
HTTP_HOST x.x.x.x
SERVER_SIGNATURE
<address>Apache Server at x.x.x.x Port 80</address>
SERVER_NAME x.x.x.
SERVER_ADDR 127.0.0.1
SERVER_PORT 80
REMOTE_ADDR x.x.x.x
Where x.x.x.x is user IP.
Anyone have any ideas why this happening.
RPAFenable On
RPAFsethostname On
RPAFproxy_ips 127.0.0.1
I imagine you don't have the sethostname on.
Path to mod_rpaf-2.0.so, relative to /etc/httpd/
LoadModule rpafmodule modules/modrpaf-2.0.so
RPAFenable On
RPAFsethostname On
Define our reverse proxy IP. Only substitute client IP in
when we receive a request from this IP.
RPAFproxy_ips 127.0.0.1
The header where the real client IP address is stored.
RPAFheader X-Forwarded-For
````So it have sethostname, I think maybe problem in mod_rpaf it self, so I will try to remake it on this weekend.