我正在尝试将我的 Ubuntu 18.04 VPS 配置为同时作为 nginx 网络服务器和私有(private) gitea 服务器运行。除了来 self 域的任何 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
非常感谢任何帮助。谢谢。
最佳答案
您的配置看起来不太干净。看这里https://linuxserversetup.com/tutorial/self-hosted-git-service#nginx-forwarding-with-https并向下滚动到“将 Nginx 配置文件更改为 HTTPS”。
要在子文件夹 git.example.com/git
中运行 Gitea,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
关于nginx - Gitea 和 Nginx 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54621221/