記錄一下配置的程序
前提:公網IP,服務器,域名
# 安裝nginx
yum install -y nginx
# 安裝編輯器,方便在censtos中進行編輯
yum install -y vim
vim /etc/nginx/nginx.conf
洗掉所有默認的server{}部分
# 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;
#原本在這里,都已被洗掉
}
創建gogs.conf檔案,并添加server部分
touch /etc/nginx/conf.d/gogs.conf
這里是問了能正常訪問http,后面會再進行修改,來訪問https
server{
listen 80;
server_name 二級域名.域名.com;
location / {
proxy_pass http://localhost:3000;
}
}
安裝gogs(此處省略docker的安裝)
# 獲取及安裝鏡像
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
接下來就可以用 “二級域名.域名.com” 域名訪問gogs了;
訪問并初始化gogs配置(點擊安裝后無法打開網站,先不著急,先配置SSL)

配置SSL直接使用了ceme.sh的http方式
# 會自動安裝
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"
接下來修改之前的gogs.conf檔案,注釋掉原來的,新增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;
# }
# }
至此,再訪問就可以登陸gogs了,開始注冊

創建倉庫


倉庫創建完畢,即可到倉庫頁面查看了,并復制鏈接

接下來到本地進行拉取,及推送測驗,使用CMD或vscode都可以,直接在終端輸入:
cd /code
git clone https://二級域名.域名.com/anything/anything.git
如果是私有倉庫,會提示需要輸入密碼,輸入后創建檔案并提交
touch test.py
git add .
git commot -m "first"
git push
至此,就配置完畢了!!
可能遇到的問題:
git push 遠程倉庫時,出現以下類似錯誤,‘Note about fast-forwards’ in ‘git push --help’ for details.
參考并感謝原作者:https://blog.csdn.net/weixin_42596434/article/details/88759295
原因是沒有指定本地 master 分支和遠程 origin/master 的連接
解決方案:因為遠程倉庫新建時,有LIENCE,由于本地倉庫和遠程倉庫有不同的開始點,也就是兩個倉庫沒有共同的commit出現,無法提交,此時我們需要allow-unrelated-histories,也就是我們的 pull 命令改為下面這樣的:
git pull origin master --allow-unrelated-histories
如果設定了默認分支,可以這樣寫:
git pull --allow-unrelated-histories
然后 git push 就可以了,
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/247265.html
標籤:其他
下一篇:linux安裝Jenkins
