我的服务器上有一个nginx-container作为反向代理。我用服务器git。我将nginx-conf文件拆分为多个文件,并将所有文件包含在default.conf文件中。然后我重建了nginx-container并启动它。之后我就不会拉存储库了。
git-repository位于服务器上的以下路径下:
此路径存在于nginx-container中,并且已安装到服务器上。
我的nginx-conf看起来像这样:
server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
server_name mySite.de;
include snippets/ssl-mySite.de;
include snippets/ssl-params.conf;
location /git(/.*) {
root /mnt/bigdata/git;
client_max_body_size 0; # Git pushes can be massive, just to make sure nginx doesn't suddenly cut the connection add this.
auth_basic "Git Login"; # Whatever text will do.
auth_basic_user_file "/mnt/bigdata/git/htpasswd";
include /etc/nginx/fastcgi_params; # Include the default fastcgi configs
fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend; # Tells fastcgi to pass the request to the git http backend executable
fastcgi_param GIT_HTTP_EXPORT_ALL "";
fastcgi_param GIT_PROJECT_ROOT /mnt/bigdata/git; # /mnt/bigdata/git is the location of all of your git repositories.
fastcgi_param REMOTE_USER $remote_user;
fastcgi_param PATH_INFO $1; # Takes the capture group from our location directive and gives git that.
fastcgi_pass unix:/var/run/fcgiwrap.socket; # Pass the request to fastcgi
}
}
我的nginx日志中出现以下错误:
2018/03/03 20:44:16 [error] 20#20: *1 open() "/etc/nginx/html/git/Testing.git/info/refs" failed (2: No such file or directory), client: 135.21.244.72, server: mySite.de, request: "GET /git/Testing.git/info/refs?service=git-upload-pack HTTP/1.1", host: "mySite.de"
135.21.244.72 - - [03/Mar/2018:20:44:16 +0000] "GET /git/Testing.git/info/refs?service=git-upload-pack HTTP/1.1" 404 169 "-" "git/2.7.4" "-"
所以nginx试图打开/ etc / nginx / html / git ....看起来好像root命令没有任何效果。我将nginx-conf更改为以下内容:
...
root /mnt/bigdata/git;
location /git(/.*) {
client_max_body_size 0; # Git pushes can be massive, just to make sure nginx doesn't suddenly cut the connection add this.
...
nginx错误:
2018/03/03 20:49:33 [error] 20#20: *1 open() "/mnt/bigdata/git/git/Testing.git/info/refs" failed (2: No such file or directory), client: 135.21.244.72, server: mySite.de, request: "GET /git/Testing.git/info/refs?service=git-upload-pack HTTP/1.1", host: "mySite.de"
135.21.244.72 - - [03/Mar/2018:20:49:33 +0000] "GET /git/Testing.git/info/refs?service=git-upload-pack HTTP/1.1" 404 169 "-" "git/2.7.4" "-"
确定/ mnt / bigdata / git / git ...不存在所以我必须删除/ git标记并将其更改为:
...
root /mnt/bigdata;
location /git(/.*) {
client_max_body_size 0; # Git pushes can be massive, just to make sure nginx doesn't suddenly cut the connection add this.
...
的nginx-日志:
135.21.244.72 - - [03/Mar/2018:20:51:53 +0000] "GET /git/Testing.git/info/refs?service=git-upload-pack HTTP/1.1" 200 0 "-" "git/2.7.4" "-"
135.21.244.72 - - [03/Mar/2018:20:51:53 +0000] "GET /git/Testing.git/HEAD HTTP/1.1" 200 23 "-" "git/2.7.4" "-"
这次我可以将存储库克隆到我的电脑上。但是存储库是空的:
warning: You appear to have cloned an empty repository.
这不是真的。如果我查看服务器上的Testing.git文件夹,我可以看到多个包。现在我将文件添加到空文件夹并尝试将其推送到服务器。我在终端上收到以下错误:
error: Cannot access URL https://mySite.de/git/Testing.git/, return code 22
fatal: git-http-push failed
error: failed to push some refs to 'https://mySite.de/git/Testing.git'
的nginx-日志:
135.21.244.72 - - [03/Mar/2018:20:54:37 +0000] "GET /git/Testing.git/info/refs?service=git-receive-pack HTTP/1.1" 200 0 "-" "git/2.7.4" "-"
135.21.244.72 - - [03/Mar/2018:20:54:37 +0000] "GET /git/Testing.git/HEAD HTTP/1.1" 200 23 "-" "git/2.7.4" "-"
135.21.244.72 - - [03/Mar/2018:20:54:37 +0000] "PROPFIND /git/Testing.git/ HTTP/1.1" 405 173 "-" "git/2.7.4" "-"
nginx的-dockerfile:
FROM nginx:1.13
RUN mkdir /etc/nginx/snippets
RUN mkdir -p /etc/nginx/conf-files
RUN mkdir -p /etc/ssl/certs/
RUN mkdir -p /etc/letsencrypt/live/mySite.de/
RUN mkdir -p /mnt/bigdata/git
VOLUME [ "/etc/nginx/conf-files", "/etc/letsencrypt/live/mySite.de/","/etc/ssl/certs/","/etc/conf.d/","/etc/nginx/snippets/","/mnt/bigdata/git" ]
COPY start-nginx.sh .
RUN apt-get clean && apt-get update && apt-get install -y nano spawn-fcgi fcgiwrap wget curl apache2-utils git
RUN sed -i 's/www-data/nginx/g' /etc/init.d/fcgiwrap
RUN chown nginx:nginx /etc/init.d/fcgiwrap
RUN mkdir /scripts
ADD scripts/ /scripts
EXPOSE 80
EXPOSE 443
CMD /etc/init.d/fcgiwrap start \
&& nginx -g 'daemon off;'
将配置文件从nginx更改回旧版本修复了问题。但我需要使用包含的nginx-conf!
我的旧nginx-conf:
upstream jenkins {
server 45.3.35.321:8080 fail_timeout=0;
}
upstream docker-jira {
server jira:8080;
}
upstream docker-conf {
server conf:8090;
}
upstream docker-orchestra {
server orchestra:8080;
}
upstream docker-orchestra-port {
server orchestra;
}
server {
listen 8443;
listen 8444;
listen 8019;
location / {
proxy_pass http://docker-orchestra-port:$server_port;
}
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name mySite.de;
return 301 https://mySite.de;
}
server {
# SSL configuration
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
server_name mySite.de;
include snippets/ssl-mySite.de;
include snippets/ssl-params.conf;
location ~ /git(/.*) {
root /mnt/bigdata/git;
client_max_body_size 0; # Git pushes can be massive, just to make sure nginx doesn't suddenly cut the connection add this.
auth_basic "Git Login"; # Whatever text will do.
auth_basic_user_file "/mnt/bigdata/git/htpasswd";
include /etc/nginx/fastcgi_params; # Include the default fastcgi configs
fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend; # Tells fastcgi to pass the request to the git http backend executable
fastcgi_param GIT_HTTP_EXPORT_ALL "";
fastcgi_param GIT_PROJECT_ROOT /mnt/bigdata/git; # /var/www/git is the location of all of your git repositories.
fastcgi_param REMOTE_USER $remote_user;
fastcgi_param PATH_INFO $1; # Takes the capture group from our location directive and gives git that.
fastcgi_pass unix:/var/run/fcgiwrap.socket; # Pass the request to fastcgi
}
location /jenkins {
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://jenkins;
proxy_redirect http://jenkins $scheme://mySite.de;
# Required for new HTTP-based CLI
proxy_http_version 1.1;
proxy_request_buffering off;
proxy_buffering off; # Required for HTTP-based CLI to work over SSL
# workaround for https://issues.jenkins-ci.org/browse/JENKINS-45651
add_header 'X-SSH-Endpoint' 'jenkins.domain.tld:50022' always;
client_max_body_size 2M;
}
location /orchestra {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://docker-orchestra/orchestra;
proxy_redirect http://docker-orchestra/orchestra https://mySite.de/orchestra;
client_max_body_size 100M;
add_header X-Frame-Options SAMEORIGIN;
}
location /jira {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://docker-jira/jira;
client_max_body_size 100M;
add_header X-Frame-Options ALLOW;
}
location /confluence {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://docker-conf/confluence;
proxy_redirect http://docker-conf/confluence https://mySite.de;
client_max_body_size 100M;
add_header X-Frame-Options SAMEORIGIN;
}
location /synchrony {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://mySite.de:8091/synchrony;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
client_max_body_size 100M;
}
}
我的新工作nginx-conf:
include /etc/nginx/conf-files/jira-confluence-upstream.conf;
include /etc/nginx/conf-files/orchestra-upstream.conf;
upstream jenkins {
server 45.3.35.321:8080 fail_timeout=0;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name mySite.de;
return 301 https://mySite.de;
}
include /etc/nginx/conf-files/orchestra-ports.conf;
server {
# SSL configuration
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
server_name mySite.de;
include snippets/ssl-mySite.de;
include snippets/ssl-params.conf;
location /git(/.*) {
root /mnt/bigdata/git;
client_max_body_size 0; # Git pushes can be massive, just to make sure nginx doesn't suddenly cut the connection add this.
auth_basic "Git Login"; # Whatever text will do.
auth_basic_user_file "/mnt/bigdata/git/htpasswd";
include /etc/nginx/fastcgi_params; # Include the default fastcgi configs
fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend; # Tells fastcgi to pass the request to the git http backend executable
fastcgi_param GIT_HTTP_EXPORT_ALL "";
fastcgi_param GIT_PROJECT_ROOT /mnt/bigdata/git; # /mnt/bigdata/git is the location of all of your git repositories.
fastcgi_param REMOTE_USER $remote_user;
fastcgi_param PATH_INFO $1; # Takes the capture group from our location directive and gives git that.
fastcgi_pass unix:/var/run/fcgiwrap.socket; # Pass the request to fastcgi
}
location /jenkins {
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://jenkins;
proxy_redirect http://jenkins $scheme://mySite.de;
# Required for new HTTP-based CLI
proxy_http_version 1.1;
proxy_request_buffering off;
proxy_buffering off; # Required for HTTP-based CLI to work over SSL
# workaround for https://issues.jenkins-ci.org/browse/JENKINS-45651
add_header 'X-SSH-Endpoint' 'jenkins.domain.tld:50022' always;
}
include /etc/nginx/conf-files/jira-confluence-location.conf;
include /etc/nginx/conf-files/orchestra-location.conf;
}
/etc/nginx/conf-files/jira-confluence-upstream.conf:
upstream docker-jira {
server jira:8080;
}
upstream docker-conf {
server conf:8090;
}
/etc/nginx/conf-files/orchestra-upstream.conf:
upstream docker-orchestra {
server orchestra:8080;
}
upstream docker-orchestra-port {
server orchestra;
}
/etc/nginx/conf-files/orchestra-ports.conf:
server {
listen 8443;
listen 8444;
listen 8019;
location / {
proxy_pass http://docker-orchestra-port:$server_port;
}
}
/etc/nginx/conf-files/jira-confluence-location.conf:
location /jira {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://docker-jira/jira;
client_max_body_size 100M;
add_header X-Frame-Options ALLOW;
}
location /confluence {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://docker-conf/confluence;
proxy_redirect http://docker-conf/confluence https://MySite.de;
client_max_body_size 100M;
add_header X-Frame-Options SAMEORIGIN;
}
location /synchrony {
proxy_set_header X-Forwarded-Host $host;
/etc/nginx/conf-files/orchestra-location.conf:
location /orchestra {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://docker-orchestra/orchestra;
proxy_redirect http://docker-orchestra/orchestra https://MySite.de/orchestra;
client_max_body_size 100M;
add_header X-Frame-Options SAMEORIGIN;
}
答案 0 :(得分:1)
我只需要进入服务器上的git-repository并运行:
sudo git update-server-info
并更改
location /git(/.*) {
到
location ~ /git(/.*) {