0

I'm a web developer. When I start developing a website and my client's domain has to point to another server until the website I'm developing is ready, what I used to do was:

1) Add their domain to my server 2) Edit my hosts file and point the domain to my server's IP.

The problem with the above setup is, clients can't see the website I'm developing, so I created a domain to host their websites temporarily until they are ready. So:

mydomain.com/client1
mydomain.com/client2
mydomain.com/client3

Let's suppose I'm developing a website for xyz.com. To avoid having to do major changes to transfer the website from mydomain.com/xyz to xyz.com (which is also in my server), I want mydomain.com/client1 to load the files that are in the xyz root folder. This way transferring mydomain.com/xyz to xyz.com would be as simple as a dns record change.

So, this is my vhost for xyz.com:

server {
      error_log /var/log/nginx/vhost-error_log warn;
      listen 1.1.1.1:80;
      server_name mydomain.com www.mydomain.com;
      access_log /usr/local/apache/domlogs/mydomain.com-bytes_log bytes_log;
      access_log /usr/local/apache/domlogs/mydomain.com combined;
      root /home/mydomain/public_html;

  location ^~ /xyz {
  root /home/xyz/public_html;

  }
  location / {
      location ~.*\.(3gp|gif|jpg|jpeg|png|ico|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|html|htm|txt|js|css|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso)$ {
      expires 1d;
      try_files $uri @backend;
      }
      error_page 405 = @backend;
      add_header X-Cache "HIT from Backend";
      proxy_pass http://1.1.1.1:8081;
      include proxy.inc;
      }
      location @backend {
      internal;
      proxy_pass http://1.1.1.1:8081;
      include proxy.inc;
      }
      location ~ .*\.(php|jsp|cgi|pl|py)?$ {
      proxy_pass http://1.1.1.1:8081;
      include proxy.inc;
      }
      location ~ /\.ht {
      deny all;
      }
    }

Looks fine, but when I access it, I get this:

403 Forbidden

I also tried using alias, didn't work. Tried with and without the "^~".

What am I doing wrong?

2 Answers2

0

well you didn't define any index, so I assume the server is trying to list the content of the folder, which is forbidden because you didn't allow auto indexing,

Try adding

index index.html index.whatever;

Inside the /xyz block

Or if you just want to list the folder contents use

autoindex on;
Mohammad AbuShady
  • 40,884
  • 11
  • 78
  • 89
0

The correct answer was nginx reverse proxy multiple backends

Your should add these lines to Server or location margin.



    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

Besides this, You should increase hash size, add these two lines.



    proxy_headers_hash_max_size 51200;
    proxy_headers_hash_bucket_size 6400;

Community
  • 1
  • 1
Tenyi
  • 11
  • 2