# gogs **Repository Path**: lianqi_1/gogs ## Basic Information - **Project Name**: gogs - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-04-13 - **Last Updated**: 2024-04-29 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 0. Linux https://www.runoob.com/linux/linux-tutorial.html ![img](./assets/Untitled.f520a049.png) # 1. Git ssh ```bash # 如何多平台使用多 SSH? ``` # 2. Gogs ```bash # 列出所有可更新的软件清单 yum check-update # 更新所有软件 yum update # 安装指定软件 yum install # 更新指定软件 yum update # 删除 yum remove # yum -y remove git yum install git which git ``` ```bash # https://gogs.io/ # Ubuntu 18.04 64位 # centos7.9 ``` 1\. 购买 ECS; 2\. 配置安全组规则; ![image-20240413103626540](./assets/image-20240413103626540.png) 3\. 公网 IP:`47.98.254.207`、`121.43.188.126`; ```bash # 可以通过官方的 Workbench 远程连接 # 或者通过普通的命令行工具连接 # 或者通过 Xshell 连接 https://www.xshell.com/zh/free-for-home-school/ ssh root@47.98.254.207 # 登录 ``` 4\. 安装 Git; ```bash # ubuntu apt --help sudo apt update apt install git # centos yum update yum install git git --version ``` 5\. 创建用户; ```bash # 查看当前用户 who whoami w # 查看所有用户 ls /home # 创建用户 userdel ifer adduser ifer # 一路回车 su ifer # switch user git # 比如我登录的用户是 ifer,cd ~ 表示进到 /home/ifer # / 表示进到当前用户的根,有 home、dev、bin 等目录 cd ~ pwd # 查看当前所在目录路径 ls # 列出当前目录文件 ``` 6\. 下载文件并解压; ```bash # 下载文件,在 gogs 官网可以找到对应下载链接 wget https://dl.gogs.io/0.11.91/gogs_0.11.91_linux_amd64.tar.gz ls # 解压到当前目录 # x => extract,z => gz tar -xzvf gogs_0.11.91_linux_amd64.tar.gz ls ``` 7\. 启动 gogs 并安装; ```bash cd gogs curl ip.sb # 查看 IP ./gogs web # 启动 gogs http://121.40.238.160:3000 # 安装 gogs,注意是 http # 修改数据库类型、运行系统用户(ifer)、域名、使用内置SSH服务器、应用 URL(端口保持 3000) ``` 8\. 注册 gogs 账号,测试仓库; ```bash # 注册账号 xxx # C:\Users\dangp\.ssh\id_rsa.pub # 添加 SSH # 创建仓库 # 以 SSH 形式克隆仓库 # 编写代码 # 提交测试 ``` 9\. 后台启动 gogs; ```bash nohup ./gogs web & ``` 10\. 期望不带端口号能访问 gogs; 思路:利用 Nginx 开个 80 的服务器,然后通过 proxy_pass 转发到这个 3000 的服务器。 ````bash # 1. 安装 Nginx su # 进入 root cd ~ # 进入 /root,注意 ~ 和 / 的差异 ls # 推荐官方安装 https://nginx.org/en/linux_packages.html#RHEL # yum install nginx # centos # apt install nginx # ubuntu nginx -v # Ubuntu # cd /etc/nginx/sites-available/ # ls # cat default # vim default # location / { # # ... # proxy_pass http://127.0.0.1:3000; # } # 2. 启动 Nginx nginx -s reload service nginx start service nginx stop service nginx restart # centos7.9 使用 yum install nginx 的安装方式后,找不到上面的目录 # centos 重新安装最新版的 nginx # 卸载 nginx # 1. root 身份登录 # 2. systemctl stop nginx # 3. yum remove nginx # 4. 删除相关配置文件和目录:/etc/nginx/、/usr/share/nginx/html # 5. nginx -v # 3. 配置 Nginx cat /etc/nginx/nginx.conf cd /etc/nginx/conf.d/ ls cp default.conf default.conf.bak # 备份默认的配置文件 # mv default.conf.bak default.conf # 修改文件名 vim default.conf ```bash server { listen 80; server_name localhost; location / { # ... # 注意最后是有分号的 proxy_pass http://127.0.0.1:3000; } // ... } ``` nginx -s reload # 重启 nginx service nginx start # http://121.40.238.160/ # 注意:如果发现前面的配置文件写错了,必须进到 root 下重新编辑 # su # vim /etc/nginx/conf.d/default.conf ```` 😊 **问题:**新建的仓库,README 中显示的有端口号。 ```bash git remote add origin http://121.40.238.160:3000/ifer/helo.git ``` ```bash su ifer cd ~ pwd # /home/ifer cd gogs/custom/conf ls vim app.ini # 去掉 ROOT_URL 的端口 cd ~ ps -ef | grep gogs # 找到 ./gogs/web 的 PID kill 18846 ls cd gogs nohup ./gogs web & ``` 😒 处理图片出不来的问题,`cd gogs/custom/conf/app.init` ```bash cd ~ # /home/ifer vim gogs/custom/conf/app.ini [picture] DISABLE_GRAVATAR = true ENABLE_FEDERATED_AVATAR = true # 重启 gogs ps -ef | grep gogs # 找到 ./gogs/web 的 PID kill 18846 ls cd gogs # cd ~/gogs 或 cd /home/ifer/gogs nohup ./gogs web & ``` # 3. Nginx ```bash yum install -y nginx nginx -v nginx -V yum list | grep nginx whereis nginx cd /etc/nginx # 启动 cd /usr/sbin ./nginx 或 /usr/sbin/nginx ps -ef | grep nginx # 列出进程 ps -C nginx -o pid # 查看进程 nginx -t # 检测配置语法 nginx -s reload nginx -s stop nginx -s quit # 优雅停止 which nginx cd /usr/share/nginx # 404、500 界面 # 卸载 nginx ps -ef | grep nginx nginx -s stop ps -C nginx -o pid whereis nginx /usr/sbin/nginx ps -ef | grep nginx kill -9 pid find / -name nginx # 列出所有 nginx 相关的文件 rm -rf /usr/lib64/nginx rm -rf /usr/share/nginx // ... ``` ```bash # 彻底删除 nginx // ... # 如果设置了 nginx 的开机启动 chkconfig nginx off rm -rf /etc/init.d/nginx yum list | grep nginx yum remove nginx ``` https://nginx.org/en/linux_packages.html#RHEL ```bash nginx -v # sudo 是 Ubuntu 的,centos 无需 sudo sudo yum install yum-utils vim /etc/yum.repos.d/nginx.repo // ... # 粘贴 # sudo yum-config-manager --enable nginx-mainline sudo yum install nginx yum list grep list whereis nginx ``` ```bash IP => 多个域名 ``` 🤔 如果不能正常访问,配置安全规则,开启端口号。 ```bash whereis nginx ``` # 4. Domain 1\. 购买弹性云服务器 ESC(中国香港无需备案); ![image-20240419182747842](./assets/image-20240419182747842.png) 2\. Xshell 连接弹性公网 IP `94.74.123.123`; 3\. 安装 [Nginx](https://nginx.org/en/linux_packages.html#RHEL); ```bash yum list | grep nginx whereis nginx # 查看 /usr/sbin/nginx # 启动 ps -C nginx -o pid # 查看相关 PID 94.74.123.123 # 访问测试下 ``` 4\. [域名解析](https://console.huaweicloud.com/dns/?agencyId=5487ee518e9b42c78cd90d40dcd5db7f®ion=ap-southeast-1&locale=zh-cn#/dns/publiczones); ```bash # @ => zhihur.com # www => www.zhihur.com ``` image-20240419183836999 image-20240419183958100 ```bash # https://zhihur.com # https://www.zhihur.com # http://zhihur.com # http://www.zhihur.com ``` 5\. 配置 Nginx; ```bash whereis nginx cd /etc/nginx # 配置文件目录 ls mkdir vhosts cd vhosts # 在此目录新建 zhihur.conf ls vim zhihur.conf ``` ```yaml server { listen 80; server_name pengsiqin.com; location / { # 网站主页路径。此路径仅供参考,具体请您按照实际目录操作。 # 例如,您的网站运行目录在 /workspace/icoding 下,则填写 /workspace/icoding root /workspace/icoding; index index.html index.htm; } } ``` ```bash cat zhihur.conf cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak # 备份 cd /etc/nginx/ vim nginx.conf ``` ```yam http { # 引入自定义配置文件 include /etc/nginx/vhosts/*.conf; include /etc/nginx/conf.d/*.conf; } ``` ```bash nginx -t ``` 🎉 新建存放项目的目录。 ```bash mkdir -p /workspace/icoding cd /workspace/icoding ll # 上次文件 nginx -s reload ``` 6\. 配置 SSL 证书; 购买证书 => 申请证书 => DNS 验证(添加记录集) => 再次 DNS 验证 => 下载签发后的证书。 image-20240419191619426 image-20240419192425513 image-20240419193023780 image-20240419193258933 7\. Nginx 安装证书; [阿里云](https://help.aliyun.com/zh/ssl-certificate/user-guide/install-ssl-certificates-on-nginx-servers-or-tengine-servers?spm=0.2020520163.help.dexternal.32743711JSqakW) ```bash mkdir -p /etc/nginx/vhosts/cert cd /etc/nginx/vhosts/cert # 将下载的本地证书和私钥文件上次至此目录 ``` 修改 Nginx 配置。 ```yaml vim /etc/nginx/vhosts/pengsiqin.conf ``` ```yaml # 以下属性中,以 SSL 开头的属性表示与证书配置有关 server { # 配置 HTTPS 的默认访问端口为 443 # 如果未在此处配置 HTTPS 的默认访问端口,可能会造成 Nginx 无法启动 # 如果您使用 Nginx1.15.0 及以上版本,请使用 listen 443 ssl 代替 listen 443 和 ssl on listen 443 ssl; # 填写绑定证书的域名 server_name pengsiqin.com; # 证书文件名称 ssl_certificate vhosts/cert/scs1713525534199_pengsiqin.com_server.crt; # 私钥文件名称 ssl_certificate_key vhosts/cert/scs1713525534199_pengsiqin.com_server.key; # 指定客户端可以重用会话参数的时间(超时之后不可使用) ssl_session_timeout 5m; # 表示使用的加密套件的类型 ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; # 表示使用的 TLS 协议的类型,您需要自行评估是否配置 TLSv1.1 协议 ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3; # 设置协商加密算法时,优先使用我们服务端的加密套件,而不是客户端浏览器的加密套件 ssl_prefer_server_ciphers on; location / { # Web 网站程序存放目录 root /workspace/icoding; index index.html index.htm; } } # 设置 HTTP 请求自动跳转 HTTPS # 如果您希望所有的 HTTP 访问自动跳转到 HTTPS 页面,则可以在需要跳转的HTTP站点下添加以下 rewrite 语句 server { listen 80; # 需要将 yourdomain 替换成证书绑定的域名 server_name pengsiqin.com; # 将所有 HTTP 请求通过 rewrite 指令重定向到 HTTPS rewrite ^(.*) https://$server_name$1 permanent; location / { root /workspace/icoding; index index.html index.htm; } } ``` ```bash nginx -t nginx -s reload ``` 8\. Gzip; `nginx.conf` ```yaml # 开启压缩功能,on 表示开启 off 表示关闭,默认是 off gzip on; #表示允许压缩的页面最小字节数,页面字节数从header头的Content-Length中获取。默认值是0,表示不管页面多大都进行压缩,建议设置成大于1K。如果小于1K可能会越压越大。即:小于设置值的文件将不会压缩 gzip_min_length 1k; # 设置压缩所需要的缓冲区大小 gzip_buffers 4 32k; # 设置gzip压缩针对的HTTP协议版本 gzip_http_version 1.1; # gzip 压缩级别,1-9,数字越大压缩的越好(一般选择4-6),也越占用CPU时间 gzip_comp_level 6; gzip_types text/css text/xml application/javascript; # 是否在http header中添加Vary: Accept-Encoding,建议开启 gzip_vary on; ``` ```bash events { use epoll; worker_connections 51200; multi_accept on; } http { gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.1; gzip_comp_level 6; gzip_types application/atom+xml application/geo+json application/javascript application/x-javascript application/json application/ld+json application/manifest+json application/rdf+xml application/rss+xml application/xhtml+xml application/xml font/eot font/otf font/ttf image/svg+xml image/jpeg image/gif image/png text/css text/javascript text/plain text/xml; gzip_vary on; gzip_disable "MSIE [1-6]\."; } ``` ```bash nginx -s reload ``` image-20240419200507953 # 5. Aliyun image-20240422201108927 > 阿里云添加证书解析记录 ~~~ # 6. Node https://nodejs.org/en/download/package-manager ```bash # installs NVM (Node Version Manager) curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash cd /root/.nvm sh install.sh # 重启命令行 # 如果上面命令不能用 # https://unix.stackexchange.com/questions/448096/trying-to-execute-a-sh-file-however-i-get-the-error-configuration-absent-in # chmod a+rx install.sh # ./install.sh nvm ls-remote # download and install Node.js nvm install 20 nvm install 16 # 注意 centos7.9 对 node18.x 不支持,需要自己 hack,这里直接换成 Ubuntu 系统了 nvm use node版本 node -v npm i hexo-cli -g hexo version ``` # 7. Hexo https://hexo.io/docs/helpers.html#toc ```bash npm i hexo-cli -g hexo version # aliyun 拉取 public # pm2 启动 # nginx 转发 # 流水线... # 查看 Nginx 状态 service --status-all | grep 'nginx' # 查看 80 端口是否跑起来 netstat -tln sudo service nginx stop sudo service nginx start sudo service nginx restart # Nginx 是后台服务一般会随系统启动,如果没有,可以运行如下命令 sudo systemctl enable nginx cat /etc/nginx/conf.d/default.conf server { listen 80; # 服务器名 server_name localhost; #access_log /var/log/nginx/host.access.log main; location / { root /usr/share/nginx/html; index index.html index.htm; proxy_pass http://127.0.0.1:3000; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } } # sudo vim default ```