Record the configuration process
Prerequisite: public IP, server, domain name
# 安装nginx
yum install -y nginx
# 安装编辑器,方便在censtos中进行编辑
yum install -y vim
vim /etc/nginx/nginx.conf
Delete all default server{} parts
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
#原本在这里,都已被删除
}
Create gogs.conf file and add server part
touch /etc/nginx/conf.d/gogs.conf
Here is a question about the normal access to http, and I will modify it later to access https
server{
listen 80;
server_name 二级域名.域名.com;
location / {
proxy_pass http://localhost:3000;
}
}
Install gogs (the installation of docker is omitted here)
# 获取及安装镜像
docker pull gogs/gogs:0.12
mkdir /docker/gogs
docker run -d --name=gogs -p 22222:22 -p 3000:3000 -v /docker/gogs:/data gogs/gogs:0.12
Then you can use the "second-level domain name. domain name. com" domain name to access gogs;
Visit and initialize gogs configuration (you can't open the website after clicking install, don't worry, configure SSL first)
configuration SSL directly uses the http method of ceme.sh
# 会自动安装
curl https://get.acme.sh | sh
cd ~/.acme.sh/
# 生成证书
./acme.sh --issue -d 二级域名.域名.com --nginx
mkdir /etc/nginx/ssl/二级域名
./acme.sh --install-cert -d 二级域名.域名.com \
--key-file /etc/nginx/ssl/二级域名/key.pem \
--fullchain-file /etc/nginx/ssl/二级域名/cert.pem \
--reloadcmd "service nginx force-reload"
Next, modify the previous gogs.conf file, comment out the original, and add SSL
server {
listen 443 ssl;
server_name 二级域名.域名.com;
ssl_certificate /etc/nginx/ssl/二级域名/cert.pem;
ssl_certificate_key /etc/nginx/ssl/二级域名/key.pem;
location / {
proxy_pass http://localhost:3000;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
}
}
# 以下部分表示重定向 HTTP 请求到 HTTPS
server {
listen 80;
server_name 二级域名.域名.com;
return 301 https://$host$request_uri;
}
# server{
# listen 80;
# server_name git.niceclark.com;
# location / {
# proxy_pass http://localhost:3000;
# }
# }
At this point, you can log in to gogs when you visit again, and start to register.
Create a warehouse
After the warehouse is created, you can go to the warehouse page to view, and copy the link.
Next , you can pull it locally and push it for testing. You can use CMD or vscode. Enter directly in the terminal:
cd /code
git clone https://二级域名.域名.com/anything/anything.git
If it is a private warehouse, you will be prompted to enter a password. After entering, create a file and submit
touch test.py
git add .
git commot -m "first"
git push
At this point, the configuration is complete! !
Possible problems:
When git push remote warehouse, the following similar error occurred,'Note about fast-forwards' in'git push --help' for details.
Reference and thank the original author: https: //blog.csdn.net/weixin_42596434/article/details/88759295
The reason is that the connection between the local master branch and the remote origin/master is not specified
Solution: When the remote warehouse is newly built, there is LIENCE. Because the local warehouse and the remote warehouse have different starting points, that is, the two warehouses do not have a common commit and cannot be submitted. At this time, we need allow-unrelated-histories. That is, our pull command is changed to the following:
git pull origin master --allow-unrelated-histories
If the default branch is set, you can write:
git pull --allow-unrelated-histories
Then git push is fine.