Nginx 的安装
解压 nginx
tar zxvf nginx-1.24.0.tar.gz
进入 nginx目录
cd nginx-1.24.0
查看 nginx-1.24.0 目录下有什么
ls
auto CHANGES CHANGES.ru conf configure contrib html LICENSE man README src
尝试安装 :
./configure
checking for OS
+ Linux 3.10.0-693.el7.x86_64 x86_64
checking for C compiler ... not found
./configure: error: C compiler cc is not found
//原因 缺少gcc
//解决方式
//安装 gcc
yum install -y gcc
//下载下载完毕后 正常安装
./configure --prefix=/usr/local/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 这个库
解决办法
安装perl 库
yum install -y pcre pcre-devel
接着
./configure --prefix=/usr/local/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.
报错原因
缺少zlib 库
解决方式
安装zlib库
yum install -y zlib zlib-devel
接着
./configure --prefix=/usr/local/nginx
如果没有问题了 我们就 make
输入
make
然后就
make install
启动nginx
首先进入安装好的目录/usr/local/nginx/sbin
cd /usr/local/nginx/sbin/
然后看看 sbin目录下有什么
有一个nginx 可执行文件
我么只要输入./nginx就能将这个服务启动起来了
启动
./nginx
#快速停止
./nginx -s stop
#优雅关闭,在退出前完成已经接受连接请求
./nginx -s quit
重新加载配置
./nginx -s reload
//启动完成后我们看看是不是真正请起来了
打开浏览器
输入你的ip地址
假设我的ip地址为
192.168.66.136
发现启动访问不了
//出现这个的原因是
由于防火墙的干扰 导致我们访问不到
解决办法
关闭防火墙
systemctl stop firewalld.service
或
禁止防火墙开机启动
systemctl disable firewalld.service
我们重新访问一下
打开浏览器
输入
192.168.66.136
出现以下内容表示成功
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.
Thank you for using nginx.
关于防火墙的操作
关闭防火墙
systemctl stop firewalld.service
禁止防火墙开机启动
systemctl disable firewalld.service
放行端口
firewall-cmd --zone=public -add-port=80/tcp --permanent
重启防火墙
firewall-cmd --reload
安装成系统服务
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=/usr/local/nginx/logs/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=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecQuit=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
wantedBy=multi-user.target
重新加载系统服务
systemctl daemon-reload
再看看
ps -ef | grep nginx
root 79990 1 0 20:10 ? 00:00:00 nginx: master process ./nginx
nobody 79991 79990 0 20:10 ? 00:00:00 nginx: worker process
root 114217 44026 0 20:48 pts/0 00:00:00 grep --color=auto nginx
我们将nginx 关了
./nginx -s stop
root 115229 44026 0 20:49 pts/0 00:00:00 grep --color=auto nginx
#启动
systemctl start nginx
# 查看状态
systemctl status nginx
启动服务
systemctl start nginx.service
开机启动
systemctl enable nginx.service