安装Nginx有两种方式:yum安装和源码安装。 通过yum安装比较简单就不过多赘述直接yum install nginx就好了!下面主要介绍通过编译安装Nginx流程与注意事项!
deepin安装nginx参考:Deepin编译安装nginx
1:下载nginx源码包
http://nginx.org/en/download.html
选择需要的nginx版本,下载xxx.tar.gz包
cd /tmp
wget http://nginx.org/download/nginx-1.14.1.tar.gz
tar -zxvf nginx-1.14.1.tar.gz
cd nginx-1.14.1
2:安装前准备
添加禁止登陆的用户
groupadd nginx
useradd -g nginx -s /sbin/nologin nginx
创建文件路径
mkdir -p /var/run/nginx
mkdir -p /var/log/nginx
mkdir -p /usr/local/nginx/log
安装扩展依赖
yum install gcc gcc-c++ automake pcre pcre-devel zlip zlib-devel openssl openssl-devel
3:编译参数配置
./configure --prefix=/usr/local/nginx --with-pcre --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --user=nginx --group=nginx --modules-path=/usr/local/nginx/modules --with-http_ssl_module --pid-path=/usr/local/nginx/nginx.pid
4:编译安装
make && make install
5:配置环境变量
vim /etc/profile.d/nginx.sh
export NGINX_HOME=/usr/local/nginx
export PATH=$PATH:$NGINX_HOME/sbin
source /etc/profile
6:将nginx加入到systemctl中
vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/nginx.pid
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
chmod 754 /usr/lib/systemd/system/nginx.service
7:Nginx常用操作
systemctl start nginx # 启动nginx
systemctl stop nginx # 关闭nginx
systemctl reload nginx # 重新加载nginx配置
systemctl restart nginx # 重启nginx
本文地址:https://blog.csdn.net/web_snail/article/details/112319965