• 创建ssh公钥和私钥 (最好保存到默认位置, 不然一会儿使用私钥的时候还是从默认位置读取的)
ssh-keygen -m PEM -t rsa -b 4096 -C "website@admin.com"
一路回车就好了
  • 默认公钥和私钥存储于用户家目录 .ssh目录下
[root@localhost .ssh]# pwd
/root/.ssh
[root@localhost .ssh]# ls -la
总用量 28
drwx------. 2 root root    81 7月   7 06:29 .
dr-xr-x---. 7 root root  4096 7月   7 06:20 ..
-rw-------. 1 root root  3243 7月   7 06:29 id_rsa
-rw-r--r--. 1 root root   742 7月   7 06:29 id_rsa.pub
  • 配置代码仓库设置
一般在代码仓库, 设置, 部署公钥 下面

然后就可以愉快的克隆啦


如果是服务端测服正服需要使用一样的发布

拷贝正服的 ~/.ssh/id_rsa,id_rsa.pub 到测服该目录
执行
chmod 600 ~/.ssh/id_rsa
chmod 644 ~/.ssh/id_rsa.pub
git config --global user.email fabu@qq.com
git config --global user.name fabu
同样的git配置完成

nginx转发请求时出现错误: 6009#0: *1 connect() to 127.0.0.1:9501 failed (13: Permission denied) while connecting to upstream

  • 错误日志
[root@localhost code]# vim + /var/log/nginx/error.log
2020/07/06 21:52:21 [error] 6009#0: *6 no live upstreams while connecting to upstream, client: 192.168.2.80, server: _, request: "GET /https/ HTTP/1.1", upstream: "https://www.baidu.com/", host: "192.168.2.140"
2020/07/06 21:52:29 [crit] 6009#0: *1 connect() to 127.0.0.1:9501 failed (13: Permission denied) while connecting to upstream, client: 192.168.2.80, server: _, request: "GET /report/ HTTP/1.1", upstream: "http://127.0.0.1:9501/report/", host: "192.168.2.140"
  • nginx转发环境
    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;

        location /https/ {
            proxy_pass https://www.baidu.com/;
        }

        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location /report/ {
            proxy_pass http://127.0.0.1:9501/;
        }

        location / {
        }

        error_page 404 /404.html;
            location = /40x.html {
        }
  • 过的第一个坑
查了很多资料说是权限问题, 于是
vim /etc/nginx/nginx.conf
把其中的 user nginx;  改为 user root; 重启nginx不管用, 然后又改回去了
  • 执行了下面一条命令, nginx都不需要重启, 就正常了, 可以正常访问 /https/ 的转发, 但是 /report/ 转发还是报错了
setsebool -P httpd_can_network_connect 1
  • /report/ 报错内容
2020/07/06 21:54:02 [error] 6009#0: *10 open() "/usr/share/nginx/html/home/msg/data/personalcontent" failed (2: No such file or directory), client: 192.168.2.80, server: _, request: "GET /home/msg/data/personalcontent?num=8&indextype=manht&_req_seqid=3114502296&asyn=1&t=1594086842083&sid=31906_1445_31325_32139_31254_32046_32230_31709_32258_26350 HTTP/1.1", host: "192.168.2.140", referrer: "http://192.168.2.140/https/"
  • 解决过程
把report的配置移动到https的转发配置后面重启nginx就好了

测试环境, centos8下通过yum install nginx安装的nginx, php7.3

  • 查询nginx配置, 获取可以执行脚本的目录
[root@localhost ~]# cat /etc/nginx/nginx.conf

...
root         /usr/share/nginx/html;
可以找到我们可以执行的默认目录为 /usr/share/nginx/html
  • 测试完结的目录文件状态
[root@localhost ~]# cd /usr/share/nginx/html
[root@localhost html]# ll -la
总用量 44
drwxr-xr-x. 2 root root   173 7月   6 12:00 .
drwxr-xr-x. 4 root root    33 7月   6 00:55 ..
-rw-r--r--. 1 root root  3971 10月  7 2019 404.html
-rw-r--r--. 1 root root  4020 10月  7 2019 50x.html
-rw-r--r--. 1 root root  4057 10月  7 2019 index.html
-rw-r--r--. 1 root root   368 10月  7 2019 nginx-logo.png
-rw-r--r--. 1 root root  4148 10月  7 2019 poweredby.png
-rw-r--r--. 1 root root   497 7月   6 03:25 publish_code.php
-rw-r--r--. 1 root root 12288 7月   6 03:26 .publish_code.php.swp
-rwxrwxrwx. 1 root root    20 7月   6 03:18 test_shell.sh
  • 编写用于发布的php脚本
[root@localhost html]# vim publish_code.php 
<?php
$cmd = isset($_REQUEST['cmd']) ? $_REQUEST['cmd'] : '';
$cmd = str_replace(["../","./","/"],"",$cmd);
if(!$cmd) {
    die('参数不能为空');
}
echo $cmd;
echo "<pre>";
system('sh /usr/share/nginx/html/' . $cmd . '.sh', $status);
echo '</pre>';

if($status) {
    echo "成功";
} else {
    echo "失败";
}
  • 编写用于测试的shell脚本
[root@localhost html]# vim test_shell.sh 
#!/bin/bash
ls -la
  • 赋予脚本执行权限
chmod 777 test_shell.sh
  • 浏览器访问测试
[root@localhost html]# curl http://127.0.0.1/publish_code.php?cmd=test_shell
test_shell<pre>total 44
drwxr-xr-x. 2 root root   173 Jul  6 12:00 .
drwxr-xr-x. 4 root root    33 Jul  6 00:55 ..
-rw-r--r--. 1 root root 12288 Jul  6 03:26 .publish_code.php.swp
-rw-r--r--. 1 root root  3971 Oct  7  2019 404.html
-rw-r--r--. 1 root root  4020 Oct  7  2019 50x.html
-rw-r--r--. 1 root root  4057 Oct  7  2019 index.html
-rw-r--r--. 1 root root   368 Oct  7  2019 nginx-logo.png
-rw-r--r--. 1 root root  4148 Oct  7  2019 poweredby.png
-rw-r--r--. 1 root root   497 Jul  6 03:25 publish_code.php
-rwxrwxrwx. 1 root root    20 Jul  6 03:18 test_shell.sh
</pre>执行成功

  • 首先安装 EPEL 源:
yum install epel-release
  • 安装Remi存储库
dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm
  • 更新系统默认的php模块
dnf module reset php  #重置php模块
dnf module enable php:remi-7.3  #默认设置为remi-7.3版本
  • 安装php7.3及一些常用模块
yum -y install php php-mysqlnd php-gd php-xml php-mbstring php-ldap php-pear php-xmlrpc php-zip
  • 安装完成
[root@localhost yum.repos.d]# php -v
PHP 7.3.19 (cli) (built: Jun  9 2020 08:06:30) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.19, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.3.19, Copyright (c) 1999-2018, by Zend Technologies
  • 配置php.ini
vim /etc/php.ini

  • yum install 软件说不存在
安装Remi存储库
dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm
  • 安装htop
centos7
yum install epel-release -y
yum install htop -y

centos6
rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
yum install htop -y