目录
1、下载
官网下载地址
nginx: downloadhttps://nginx.org/en/download.html
或者从这里下载:
下载后上传服务器
解压
tar -xvf nginx-1.21.6.tar.gz
2、安装
然后进入目录
安装, --prefix=/opt/nginx安装目录的意思
./configure --prefix=/opt/nginx
报错了:
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
安装pcre-devel解决问题
yum -y install pcre-devel
再次安装
./configure --prefix=/opt/nginx
又报错:
./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.
执行:
yum install -y zlib zlib-devel
再次执行:
./configure --prefix=/opt/nginx
然后执行
make
执行:
make install
安装目录已经有文件了
启动nginx
./nginx
浏览器输入IP,默认端口是80
安装完成
3、相关问题
如果不能访问,关闭防火墙
#开启防火墙
systemctl start firewalld#关闭防火墙
systemctl stop firewalld
安装成服务的形式,创建服务脚本
vi /usr/lib/systemd/system/nginx.service
内容如下:
[Unit]
Description=nginx - web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/opt/nginx/logs/nginx.pid
ExecStartPre=/opt/nginx/sbin/nginx -t -c /opt/nginx/conf/nginx.conf
ExecStart=/opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf
ExecReload=/opt/nginx/sbin/nginx -s reload
ExecStop=/opt/nginx/sbin/nginx -s stop
ExecQuit=/opt/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
重新加载系统服务
systemctl daemon-reload
启动服务
systemctl start nginx.service
开机启动
systemctl enable firewalld.service
ps -ef|grep nginx
查出 nginx线程后,然后执行
systemctl start nginx.service
以后就可以用这样的命令去开启服务了,也可以查看状态
systemctl status nginx.service