Nginx配合github页面和主页

我试图configurationNginx使用像github页面的代理传递的域名,并且在根域上也有一个登陆页面。

有了这个configuration代理githubages工作正常,但如果我检查example.com它也转到github页面。

我的configuration是这样的:

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

它必须这样做:

example.com或www.example.com – >去我自己的着陆(这是行不通的)

example.com/repo/ – >转到user.github.io/repo。 是的,它的作品

谢谢

index指令导致内部redirect到/index.html ,所以它被匹配的location /块。

您需要一个单独的位置块来处理/index.html ,并确保它不会被location /块匹配。 如果您在index.html使用了其他任何静态资源(如图片或CSS),则还需要一个位置块来处理这些资源。 例:

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