由于我需要使用的模块比较小众化,而用appnode已经习惯了,因此我尝试看看能不能让appnode识别我自己编译的nginx.

安装appnode

使用官网的步骤,正常安装appnode即可,使用:同时安装控制中心,受控端。因为网站管理和Nginx是会冲突
先不要启动nginx
然后去软件管家中安装nginx环境和面板软件后,再自己手动卸载掉nginx的环境,这样就留下了面板进行管理了。
appnode更新了,可以直接只安装nginx的面板,就只手动安装nginx面板即可。

编译安装nginx

上面appnode安装完成后,进入面板操作一下,如果操作正常的话即可开始编译安装nginx.

安装依赖

使用:

yum update
yum install gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel -y

即可安装编译所需依赖。

下载源码

前往nginx官网:

http://nginx.org/en/download.html

选择合适的源码下载

wget http://nginx.org/download/nginx-1.18.0.tar.gz
tar -zxvf nginx-1.18.0.tar.gz

编译安装

为了使appnode的网站管理可以识别到nginx,需要保证我们编译的nginx的路径如下所示:
nginx编译路径

cd nginx-1.18.0
./configure --prefix=/usr --sbin-path=/usr/sbin/nginx  --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log
make
make install 

对应的路径如下所示:

  nginx path prefix: "/usr"
  nginx binary file: "/usr/sbin/nginx"
  nginx modules path: "/usr/modules"
  nginx configuration prefix: "/etc/nginx"
  nginx configuration file: "/etc/nginx/nginx.conf"
  nginx pid file: "/usr/logs/nginx.pid"
  nginx error log file: "/var/log/nginx/error.log"
  nginx http access log file: "/var/log/nginx/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

使用nginx -v

[root@localhost nginx-1.18.0]# nginx -v
nginx version: nginx/1.18.0

提示版本正常,安装完成。

开机启动

nano /usr/lib/systemd/system/nginx.service

输入

[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/usr/logs/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/usr/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

即可用

systemctl enable nginx

设置开机启动
以及开启、重启、状态

systemctl start nginx
systemctl restart nginx
systemctl status nginx

对接

现在对接面板与nginx

mkdir /etc/nginx/conf.d/
mkdir /var/www/

先创建两个必须用的文件夹,然后在:Nginx - 环境管理 - 添加环境 - 手动输入路径即可:
手动对接环境

然后就可以用appnode手动管理我自己编译的nginx了。

lnmp安装nginx

手动编译安装nginx速度还是太慢了。还是用lnmp.org方便
还是先去软件管家中安装nginx环境和面板软件后,再自己手动卸载掉nginx的环境,这样就留下了面板进行管理了。

安装

按照nginx的步骤正常安装即可

wget http://soft.vpser.net/lnmp/lnmp1.7.tar.gz -cO lnmp1.7.tar.gz && tar zxf lnmp1.7.tar.gz && cd lnmp1.7 && ./install.sh nginx

需要啥组件就自己往里面加。

对接

lnmp的路径如下所示:

配置项代号类型
主程序/usr/local/nginx/sbin/nginxnginx程序
主配置文件/usr/local/nginx/conf/nginx.confnginx.conf配置
服务脚本/etc/systemd/system/nginx.serviceservice脚本

按照上面的表格填入appnode - nginx - 环境管理 - 添加环境 即可

使用

mkdir /usr/local/nginx/conf/conf.d
cp /etc/systemd/system/nginx.service /usr/lib/systemd/system/nginx.service

来解决nginx面板的报错。
刷新下,如果提示需要接管的话,点击重新接管即可。然后再刷新下。

如果显示空白的话,用f12检查api报错内容,根据报错内容进行排查

appnode官方论坛上有我排错后找到原因的过程。

简单的说就是lnmp.org是直接在/etc/systemd/system/内创建nginx.service,但实际上systemctl官方路径是/usr/lib/systemd/system/

systemctl enable的作用

每一个 Unit(服务等) 都有一个配置文件,告诉 Systemd 怎么启动这个 Unit 。
Systemd 默认从目录/etc/systemd/system/读取配置文件。
但是,里面存放的大部分文件都是符号链接,指向目录/usr/lib/systemd/system/,真正的配置文件存放在那个目录。 systemctl enable 命令用于在上面两个目录之间,建立符号链接关系。

$ sudo systemctl enable clamd@scan.service
# 等同于
$ sudo ln -s '/usr/lib/systemd/system/clamd@scan.service' '/etc/systemd/system/multi-user.target.wants/clamd@scan.service'

如果配置文件里面设置了开机启动,systemctl enable命令相当于激活开机启动。

与之对应的,systemctl disable命令用于在两个目录之间,撤销符号链接关系,相当于撤销开机启动。

$ sudo systemctl disable clamd@scan.service

配置文件的后缀名,就是该 Unit 的种类,比如sshd.socket。如果省略,Systemd 默认后缀名为.service,所以sshd会被理解成sshd.service。

检查

前往appnode - nginx
测试创建网站之类的功能就行了。


参考:
请问nginx可以启用不在面板列表的模块吗
Centos 7下编译安装Nginx
NGINX systemd service file
lnmp.org
linux 中 /etc/systemd/system和/usr/lib/systemd/system 的区别

最后修改:2020 年 09 月 30 日
如果觉得我的文章对你有用,请随意赞赏