我正在转换一个Web应用程序从Apache到Nginx。 在Apache的httpd.conf中我有:
ProxyPass /proxy/ http:// ProxyPassReverse /proxy/ http://
这个想法是客户发送这个url:
http://web-server-domain/proxy/login-server-addr/loginUrl.php?user=xxx&pass=yyy
和Web服务器调用:
http://login-server-addr/loginUrl.php?user=xxx&pass=yyy
我的nginx.conf附在下面,它不工作。 目前看起来它正在调用服务器,但返回一个应用程序错误。 这似乎很有希望,但任何尝试debugging失败! 我不能跟踪任何的调用,因为nginx拒绝把它们放在错误文件中。 另外,在login服务器上放置echo语句并没有帮助哪个是奇怪的。
nginx文档对此没有太大的帮助。
任何关于如何configurationproxy_pass的build议?
谢谢!
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;
}
好的,我在我的nginxtesting平台上试了一下,在日志里得到了以下内容:
2011/08/29 22:35:31 [error] 10074#0: *1257 no host in upstream "", client: 10.103.0.9, server: localhost, request: "GET /proxy/ya.ru HTTP/1.1", host: "10.110.0.42"
所以,nginx不是一个正确的工具,上游主机不能在运行时定义。