nginx: problem configuring a proxy_pass
Posted
by
Ofer Bar
on Server Fault
See other posts from Server Fault
or by Ofer Bar
Published on 2011-08-29T16:08:40Z
Indexed on
2012/04/13
5:32 UTC
Read the original article
Hit count: 597
I'm converting a web app from apache to nginx. In apache's httpd.conf I have:
ProxyPass /proxy/ http://
ProxyPassReverse /proxy/ http://
The idea is the client send this url:
http://web-server-domain/proxy/login-server-addr/loginUrl.php?user=xxx&pass=yyy
and the web server calls:
http://login-server-addr/loginUrl.php?user=xxx&pass=yyy
My nginx.conf is attached below and it is not working. At the moment it looks like it is calling the server, but returning an application error. This seems promising but any attempt to debug this failed! I can't trace any of the calls as nginx refuses to place them in the error file. Also, placing echo statement on the login server did not help either which is weird.
The nginx documentation isn't very helpful about this.
Any suggestion on how to configure a proxy_pass?
Thanks!
user nginx;
worker_processes 1;
#error_log /var/log/nginx/error.log;
error_log /var/log/nginx/error.log notice;
#error_log /var/log/nginx/error.log info;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
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 main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
#
# The default server
#
server {
rewrite_log on;
listen 80;
server_name _;
#charset koi8-r;
#access_log logs/host.access.log main;
#root /var/www/live/html;
index index.php index.html index.htm;
location ~ ^/proxy/(.*$) {
#location /proxy/ {
# rewrite ^/proxy(.*) http://$1 break;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_buffering off;
proxy_pass http://$1;
#proxy_pass "http://173.231.134.36/messages_2.7.0/loginUser.php?userID=ofer.fly%40gmail.com&password=y4HTD93vrshMNcy2Qr5ka7ia0xcaa389f4885f59c9";
break;
}
location / {
root /var/www/live/html;
#if ( $uri ~ ^/proxy/(.*) ) {
# proxy_pass http://$1;
# break;
#}
#try_files $uri $uri/ /index.php;
}
error_page 404 /404.html;
#location = /404.html {
# root /usr/share/nginx/html;
#}
# redirect server error pages to the static page /50x.html
#
#error_page 500 502 503 504 /50x.html;
#location = /50x.html {
# root /usr/share/nginx/html;
#}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
#root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME /var/www/live/html$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# Load config files from the /etc/nginx/conf.d directory
include /etc/nginx/conf.d/*.conf;
}
© Server Fault or respective owner