0

As the title said, I got trouble making Nginx serving a subdomain. It keeps serving over and over again the main domain. Whether I ask for www.example.com or git.example.com, it keeps serving www.example.com (which is the only password protected conf). All the requests are written in the access.log and nothing is in the subdomain access.log.

Here are my conf files which I put directly in the sites-enabled folders:

main

server {
    listen 80;

    server_name www.example.com;

    root /var/www/html;
    index index.nginx-debian.html;

    location / {
            auth_basic "Login";
            auth_basic_user_file /var/www/.htpasswd;
            try_files $uri $uri/ =404;
    }

    location ~ /\. {
            deny all;
    }
}

gitlab (source : https://gitlab.com/gitlab-org/gitlab-recipes/blob/master/web-server/nginx/gitlab-omnibus-nginx.conf)

upstream gitlab-workhorse {
        server unix:/var/opt/gitlab/gitlab-workhorse/socket;
}

server {
    listen 0.0.0.0:8080;
    listen [::]:8080;
    server_name git.example.com;
    server_tokens off;
    root /opt/gitlab/embedded/service/gitlab-rails/public;
    access_log  /var/log/nginx/gitlab_access.log;
    error_log   /var/log/nginx/gitlab_error.log;
    location / {
            client_max_body_size 0;
            gzip off;
            proxy_read_timeout      300;
            proxy_connect_timeout   300;
            proxy_redirect          off;
            proxy_http_version 1.1;
            proxy_set_header    Host                $http_host;
            proxy_set_header    X-Real-IP           $remote_addr;
            proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_$
            proxy_set_header    X-Forwarded-Proto   $scheme;
            proxy_pass http://gitlab-workhorse;
    }
}

What I did so far :

  • Removed main, then Nginx is not serving anything anymore;
  • Removed gitlab, then Nginx is serving both www and gitlab as www;
  • Fresh Nginx install did not change anything.

I just spent 4 hours on this problem and could not solve it on my own or using the internet. I take any ideas !

2

Your main domain is the only vhost listening on port 80. Switch your git vhost to port 80 as well and it should work.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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