版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yikong2yuxuan/article/details/83957758
1、更新yum
yum update
2、安装依赖
yum install gcc-c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel
3、进入到 /usr/local/src目录下载nginx
wget http://nginx.org/download/nginx-1.14.0.tar.gz
4、解压
tar -zxvf nginx-1.14.0.tar.gz
5、编译
./configure --prefix=/usr --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/tem/nginx/client --http-proxy-temp-path=/var/tem/nginx/proxy --http-fastcgi-temp-path=/var/tem/nginx/fcgi --with-http_stub_status_module
6、安装
make && make install
7、启动
nginx -c /etc/nginx/nginx.conf
8、如果出现[emerg] getpwnam("nginx") failed 错误 执行
useradd -s /sbin/nologin -M nginx
id nginx
9、如果出现 [emerg] mkdir() "/var/temp/nginx/client" failed (2: No such file or directory) 错误 执行
mkdir -p /var/tem/nginx/client
10、如果您正在运行防火墙,请运行以下命令以允许HTTP和HTTPS通信:
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload
11、输入服务器地址,查看是否成功
扫描二维码关注公众号,回复:
4026653 查看本文章
12、配置nginx开机启动
切换到/lib/systemd/system/目录,创建nginx.service文件vi nginx.service
cd /lib/systemd/system
vi nginx.service
输入内容如下:
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/src/nginx/sbin/nginx
ExecReload=/usr/local/src/nginx/sbin/nginx reload
ExecStop=/usr/local/src/nginx/sbin/nginx quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
其中/usr/local/src为你的nginx安装目录
退出保存文件,然后执行命令:
systemctl enable nginx.service
systemctl start nginx.service 启动nginx
systemctl stop nginx.service 结束nginx
systemctl restart nginx.service 重启nginx
最后请求服务器,检验是否安装成功!