Recently in nginx Category
service nginx start
error.log:
2011/01/07 05:39:49 [emerg] 7180#0: eventfd() failed (38: Function not implemented)
2011/01/07 05:39:49 [alert] 7179#0: worker process 7180 exited with fatal code 2 and can not be respawn
2011/01/07 05:43:01 [emerg] 7296#0: eventfd() failed (38: Function not implemented)
2011/01/07 05:43:01 [alert] 7295#0: worker process 7296 exited with fatal code 2 and can not be respawn
[root@2hei.net /etc/nginx]# /usr/sbin/nginx -V
nginx version: nginx/0.8.53
built by gcc 4.1.2 20080704 (Red Hat 4.1.2-48)
TLS SNI support disabled
configure arguments: --user=nginx --group=nginx --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/var/run/nginx.pid --lock-path=/var/lock/subsys/nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module --with-http_perl_module --with-mail --with-file-aio --with-mail_ssl_module --with-ipv6 --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic' --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'
we can see --with-file-aio is been compiled at yum.
[root@2hei.net /etc/nginx]# yum list | grep aio
libaio.i386 0.3.106-3.2 installed
libaio.x86_64 0.3.106-3.2 installed
libsane-hpaio.x86_64 1.6.7-4.1.el5.4 installed
libaio-devel.x86_64 0.3.106-3.2 base
libaio-devel.i386 0.3.106-3.2 base
yum install libaio-devel
restart nginx still has such error.
Got a new stable version of nginx
nginx version: nginx/0.8.54
built by gcc 4.1.2 20080704 (Red Hat 4.1.2-48)
TLS SNI support disabled
configure arguments: --user=nginx --group=nginx --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --pid-path=/var/run/nginx.pid --lock-path=/var/lock/subsys/nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_perl_module --with-mail --with-mail_ssl_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic' --add-module=/builddir/build/BUILD/nginx-0.8.54/nginx-upstream-fair
download link: nginx-stable-0.8.54-1.el5.x86_64.rpm
useful link:
http://forum.nginx.org/read.php?2,23577,153119#msg-153119
http://forum.nginx.org/read.php?2,150853,150853
I have such a request, will rewrite url to google's search site,
type http://mysite/search/search.html?t=laday gaga --> http://www.google.com/search?q=lady%20gaga
I donn't want to use other tools(php/java etc.) except nginx.
For a long time googleing, finally find how to setting nginx dynamic url rewrite :)
location /search/ {
root /var/2hei.net/nginx;
if ($args){
rewrite ^/search/search.html "http://www.google.com/search?q=$arg_t?" last;
}
}
and '?' is very important, or the rewrite url will add append query string,
http://mysite/search/search.html?t=laday gaga --> http://www.google.com/search?q=lady%20gaga?t=lady%20gaga
we will get wrong rewrite url.
alse we can use $query_string
if ($query_string ~* t=(.*)){
...
}
Just enjoy it!
测试环境: nginx+resin
IP: 内网:172.16.100.10
客户端IP:123.123.123.123
测试页面: test.jsp
<%
out.println("x-forwarded-for: " + request.getHeader("x-forwarded-for"));
out.println("remote hosts: " + request.getRemoteAddr());
%>
nginx 配置一
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
wget测试
wget -O aa --header="X-Forwarded-For:192.168.0.1" "http://2hei.net/test.jsp"
页面返回结果:
x-forwarded-for: 192.168.0.1, 123.123.123.123
remote hosts: 172.16.100.10
curl测试
curl -H "X-Forwarded-For:192.168.0.1" "http://2hei.net/test.jsp"
x-forwarded-for: 192.168.0.1, 123.123.123.123
remote hosts: 172.16.100.10
nginx 配置二
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
wget测试:
wget -O aa --header="X-Forwarded-For:192.168.0.1" "http://2hei.net/test.jsp"
页面返回结果:
x-forwarded-for: 123.123.123.123
remote hosts: 172.16.100.10
curl测试
curl -H "X-Forwarded-For:192.168.0.1" "http://2hei.net/test.jsp"
x-forwarded-for: 123.123.123.123
remote hosts: 172.16.100.10
测试结果:
1、配置 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
增加了一个真实ip X-Forwarded-For,并且顺序是增加到了“后面”。
2、配置 proxy_set_header X-Forwarded-For $remote_addr;
清空了客户端伪造传入的X-Forwarded-For,
保证了使用request.getHeader("x-forwarded-for")获取的ip为真实ip,
或者用“,”分隔,截取X-Forwarded-For最后的值。
basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
其中: request.getScheme() return http but not https.
之前单独使用apache(https)+resin的方式正常,现在前面增加了一层nginx,发现问题来了,协议部分(Scheme)无法传过去,后台的resin无法获取到正确的值。
尝试了下面的配置,结果还是一无所获。
proxy_redirect off;
proxy_set_header HTTPS on;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Url-Scheme $scheme;
proxy_set_header X-Scheme $scheme;
proxy_set_header X-Nginx-Scheme $scheme;
proxy_set_header Scheme $scheme;
proxy_set_header X-FORWARDED_PROTO $scheme;
proxy_set_header X-FORWARDED_PROTO "https";
proxy_set_header X-Forwarded-Scheme "https";
proxy_set_header X-Forwarded-Proto $scheme;
real-scheme-header X-Forwarded-Proto;
今天下午好好google了一番,所有的帖子几乎翻了个遍,终于有所收获啦,重点是nginx配置完毕后,apache也要配置环境变量哦!
http://www.ruby-forum.com/topic/183450
nginx config:
=============
proxy_set_header X-Nginx-Scheme $scheme;
# nginx variable $scheme will be 'http' or 'https'.
apache config:
==============
SetEnvIf X-Nginx-Scheme "^https$" HTTPS=on
# Apache environment variable HTTPS will be 'on' or not defined.
测试代码如下:
<%
out.println("Protocol: " + request.getProtocol() + "<br>");
out.println("Scheme: " + request.getScheme() + "<br>");
out.println("Server Name: " + request.getServerName() + "<br>" );
out.println("Server Port: " + request.getServerPort() + "<br>");
%>
页面打印结果为,正常了!
Protocol: HTTP/1.0
Scheme: https
Server Name: 2hei.net
Server Port: 443




