[Share Experiences] deepin UOS Linux源代码编译安装Nginx
Tofloor
poster avatar
zizdong
deepin
Forum Operations
2023-07-14 21:41
Author

转载自:李昊哲小课

建立nginx用户和用户组

sudo groupadd nginx
sudo useradd nginx -g nginx -s /sbin/nologin -M

下载并解压nginx源代码

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

预编译源代码

sudo ./configure --prefix=/usr/local/nginx \
 --user=nginx --group=nginx \
 --with-http_stub_status_module --with-http_ssl_module \
 --with-http_realip_module --with-http_gzip_static_module \
 --with-file-aio --with-http_realip_module  

编译源代码

sudo make -j4

安装nginx

sudo make -j4 install

查看nginx版本号

sudo /usr/local/nginx/sbin/nginx -v

检查nginx配置文件是否正确

sudo /usr/local/nginx/sbin/nginx -t

启动nginx

sudo /usr/local/nginx/sbin/nginx

重新载入配置文件

sudo /usr/local/nginx/sbin/nginx -s reload

快速关闭 Nginx

sudo /usr/local/nginx/sbin/nginx -s stop

关闭Nginx

sudo /usr/local/nginx/sbin/nginx -s quit

编写启动脚本

cd /usr/lib/systemd/system/
sudo vim nginx.service
[Unit]
Description=nginx
After=network.target remote-fs.target nss-lookup.target
 
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPost=/bin/sleep 0.1
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target

重新加载服务文件

sudo systemctl daemon-reload

sudo systemctl start|stop|reload|restart|status nginx.service

开机自启:

sudo systemctl enable nginx.service

关闭开机自启:

sudo systemctl disable nginx.service

Reply Favorite View the author
All Replies
青稚°
Moderator
2023-07-14 21:42
#1

辛苦了,给优质贴带到论坛

like

Reply View the author
阿尼樱奈奈
Moderator
2023-07-14 21:42
#2

like

Reply View the author
hanzn-zzx
deepin
2023-07-14 22:03
#3

赞!like

Reply View the author
乾豫恒益
deepin
2023-07-14 22:34
#4

likelikelike

like
Reply View the author
lihaozhe
deepin
2023-08-03 01:15
#5

感谢官方的认可和推荐

Reply View the author