Nginx 将 git.example.com 转发到 www.example.com

Nginx 将 git.example.com 转发到 www.example.com

正如标题所示,我的网站 git.mad3ngineer.net 转发到 www.mad3ngineer.net。但是,我的 ci.mad3ngineer.net 使用相同的系统,但运行良好...

该网站可以访问http://git.mad3ngineer.net你可以看到它将你转到默认站点,该站点目前只是一个用 vi 制作的单调的 html 文档。但是,如果你输入http://ci.mad3ngineer.net它神奇地起作用了!!!更不用说……如果你将 /users/sign_in 添加到 git.mad3ngineer.net……像这样:git.mad3ngineer.net/users/sign_in 它也会神奇地起作用 :O……怎么会这样?我做错了什么?我已经重启了服务器,重新加载了配置,但我不明白我做错了什么。

这是我的 nginx 站点配置文件:

upstream gitlab {
  server unix:/var/opt/gitlab/gitlab-rails/sockets/gitlab.socket;
}

upstream gitlabci {
  server unix:/var/opt/gitlab/gitlab-ci/sockets/gitlab.socket;
}

server{
    listen      80 default_server;
    server_name 192.168.1.10 mad3ngineer.net www.mad3ngineer.net;

    root /var/www/mad3ngineer.net;

    location / {
        index index.php index.html index.htm;
    }

    location /gitlab {
        rewrite ^/gitlab/(.*) http://git.mad3ngineer.net$1 break;
    }
    location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;

    }
}

server{
        listen 80;
        server_name ci.mad3ngineer.net;
        server_tokens off;

        root /var/opt/gitlab/git-data;
        index index.php index.html index.htm;

        client_max_body_size 20m;

        access_log /var/log/nginx/gitlab_access.log;
        error_log  /var/log/nginx/gitlab_error.log;

        location / {
                try_files $uri $uri/index.html $uri.html @gitlabci;
        }

        location @gitlabci {
                proxy_read_timeout 300;
                proxy_connect_timeout 300; # Some requests take more than 30 seconds.
                proxy_redirect     off;

                proxy_set_header   X-Forwarded-Proto $scheme;
                proxy_set_header   Host              $http_host;
                proxy_set_header   X-Real-IP         $remote_addr;
                proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
                proxy_set_header   X-Frame-Options   SAMEORIGIN;

                proxy_pass http://gitlabci;
        }
}

server{
        listen 80;
        server_name git.mad3ngineer.net gitlab.mad3ngineer.net;
        server_tokens off;

        root /var/opt/gitlab/git-data;
        index index.php index.html index.htm;

        client_max_body_size 20m;

        access_log /var/log/nginx/gitlab_access.log;
        error_log  /var/log/nginx/gitlab_error.log;

        location / {
                try_files $uri $uri/index.html $uri.html @gitlab;
        }

        location @gitlab {
                proxy_read_timeout 300;
                proxy_connect_timeout 300; # Some requests take more than 30 seconds.
                proxy_redirect     off;

                proxy_set_header   X-Forwarded-Proto $scheme;
                proxy_set_header   Host              $http_host;
                proxy_set_header   X-Real-IP         $remote_addr;
                proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
                proxy_set_header   X-Frame-Options   SAMEORIGIN;

                proxy_pass http://gitlab;
        }
}

已解决:我必须将 git.mad3ngineer.net 的根值更改为 /var/opt/gitlab/nginx。谢谢您的回答!

答案1

您需要将两台服务器的“根”目录配置为正确的路径。

两个根集如下:

 root /var/opt/gitlab/git-data;

你的 gitlab 目录可能包含基于其生产/开发配置 yaml 文件的重定向,查找“gitlab_url”。

相关内容