Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:


and the web server calls:


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?


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/;

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 "";

   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
    #location ~ \.php$ {
    #    proxy_pass;

    # pass the PHP scripts to FastCGI server listening on
    location ~ \.php$ {
        #root           html;
        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;


share|improve this question
It sounds like you want a forward proxy and not a reverse proxy. Nginx might not be best suited for what you want to do. – Martin Fjordvald Aug 29 '11 at 17:09
@Martin F: What makes you say that? – womble Aug 29 '11 at 18:24
@Ofer Bar, have you tried to set log verbosity to debug? The configuration string for that is error_log /var/log/nginx/error.log debug;. Could you please attach a debug output to your question? – Alex Aug 29 '11 at 18:29
Hi everyone and thanks for replying. Just to clarify, I'm not trying to find the best tool to do that. The reason why I am testing nginx instead of apache is that with apache servers we're experiencing lots of servicing errors when getting images, SWF files, etc. We got a recommendation to switch to nginx because it might solve our problems, that's the purpose of the test. BTW, using debug flag doesn't work, no new info is written to the error log. I've read somewhere that nginx needs to be compiled with debug enabled for that to work. Based on the responses here, I guess I'll need to change m – oferbar Aug 29 '11 at 22:28
@womble: it seems he wants the client to tell the server which address to proxy him to, that's a standard forward proxy. Nginx was designed to be a reverse proxy and makes no attempt to be a forward proxy. While it can work in some situations it's often not optimal and can cause extra headaches. – Martin Fjordvald Aug 30 '11 at 8:37

Okay, I tried this on my nginx testbed and got the following in the log:

2011/08/29 22:35:31 [error] 10074#0: *1257 no host in upstream "", client:, server: localhost, request: "GET /proxy/ HTTP/1.1", host: ""

So, nginx is just not a right tool to do that, upstream hosts can't be defined at runtime.

share|improve this answer
They can, you just need to host your own DNS server and configure nginx to use it. – Martin Fjordvald Aug 30 '11 at 8:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.