1

I am trying to configure Nginx to use a domain like proxy pass to github pages, and also to have a landing page on the root domain.

With this configuration the proxy to githubpages work fine, but if I check example.com it goes to github pages also.

My configuration is this:

   server {
        listen 80 ;
        index index.html index.htm;
        server_name example.com www.example.com ;
        location = / {
                       index index.html;
                       root /home/landing/public_html ;  
        }
        location /  {    #this work fine
        proxy_set_header Host enlaorbita.github.io;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_pass http://user.github.io/;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
}

It have to do:

example.com or www.example.com --> go to my own landing (It doesn't work)

example.com/repo/ --> go to user.github.io/repo. Yes it works

Thanks

pablogg
  • 13
  • 3

1 Answers1

0

The index directive is causing an internal redirect to /index.html, so it's getting matched by your location / block.

You'll need a separate location block to handle /index.html and make sure it doesn't get matched by the location / block. If you have any other static resources like images or CSS used in index.html, you'll want a location block to handle those as well. Example:

server {
    listen 80;
    server_name example.com www.example.com;

    root /home/landing/public_html;

    location = / {
       index index.html;
    }

    location /index.html {
        # Empty block -- root is set above
    }

    location /static {
        # Also an empty block
        # Put your static files in /home/landing/public_html/static, and access
        # them at example.com/static/filename
    }

    location / {
        proxy_set_header Host user.github.io;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_pass http://user.github.io/;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}
longb4
  • 51
  • 5