2

我正在尝试将我的 Ubuntu 18.04 VPS 配置为同时作为 nginx 网络服务器和私有 gitea 服务器运行。我的配置大部分都在工作,除了来自我的域的任何 404 都传递到 gitea 并显示 gitea 404。我希望主域的任何用户都不要被定向到 Gitea。

客观的:

  • 除 git.domain.com 之外的任何子域都不应代理到 Gitea,应使用 https(工作)
  • 除 git.domain.com 之外的子域的任何错误都不应转到 Gitea(不工作)
  • git.domain.com 应该提供对 gitea 的 https 访问(工作)

试过:

  • Gitea 使用 location /git/ 将两者分开,并允许 location / 在尝试 url 后返回 404。这会导致 Gitea 中出现 404 错误的各种问题,或者导致 git.domain.com 不使用 nginx

启用域站点的配置:

server {

    root /var/www/example.com/html;
    index index.html index.htm index.nginx-debian.html;

    server_name git.example.com;
    location / {
            proxy_pass https://0.0.0.0:3000;
    }
server_name *.example.com;
location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
location ~ /\.ht {
    deny all;
}
    #location / {
    #        try_files $uri $uri/ =404;
    #}

listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate <path>/fullchain.pem; # managed by Certbot
ssl_certificate_key <path>/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

任何帮助是极大的赞赏。谢谢你。

4

1 回答 1

0

您的配置看起来并不干净。看看这里https://linuxserversetup.com/tutorial/self-hosted-git-service#nginx-forwarding-with-https并向下滚动到“将 Nginx 配置文件更改为 HTTPS”。

要在子文件夹中运行 Gitea git.example.com/git,Nginx 配置应该是这样的:

server {
  listen      443 ssl http2;
  listen      [::]:443 ssl http2;
  server_name git.example.com;

  root        /var/www/example.com/html;
  index       index.htm;

  location / {
    try_files $uri $uri/ /index.htm;
  }

  location /git/ {
    proxy_pass http://localhost:3000/;
  }

  # ...
}

并相应地在 Gitea 配置中

[server]
PROTOCOL         = http
DOMAIN           = git.example.com/gitea
HTTP_PORT        = 3000
ROOT_URL         = https://git.example.com/gitea
于 2022-02-03T10:53:21.357 回答