nginx 在 linux 下的安装

1.1 下载 nginx 1.6

https://nginx.org/en/download.html

最新稳定版本

wget -c https://nginx.org/download/nginx-1.16.1.tar.gz

1.2 安装nginx 编译依赖

#gcc安装,nginx源码编译需要

yum install gcc-c++

#PCRE pcre-devel 安装,nginx 的 http 模块使用 pcre 来解析正则表达式

yum install -y pcre pcre-devel

#zlib安装,nginx 使用zlib对http包的内容进行gzip

yum install -y zlib zlib-devel

#OpenSSL 安装,强大的安全套接字层密码库,nginx 不仅支持 http 协议,还支持 https(即在ssl协议上传输http)

yum install -y openssl openssl-devel

1.3 安装nginx

#根目录使用ls命令可以看到下载的nginx压缩包,然后解压

tar -zxvf nginx-1.16.1.tar.gz

#解压后进入目录

cd nginx-1.16.1

#使用默认配置

./configure

#编译安装

make

make install

#启动、停止nginx

cd /usr/local/nginx/sbin/

./nginx     #启动

./nginx -s stop  #停止,直接查找nginx进程id再使用kill命令强制杀掉进程

./nginx -s quit  #退出停止,等待nginx进程处理完任务再进行停止

./nginx -s reload  #重新加载配置文件,修改nginx.conf后使用该命令,新配置即可生效

#重启nginx,建议先停止,再启动

./nginx -s stop

./nginx

#查看nginx进程,如下返回,即为成功

ps aux|grep nginx

1.4开机自启动

#rc.local增加启动代码即可

vi /etc/rc.local

#增加一行 /usr/local/nginx/sbin/nginx,增加后保存

#设置执行权限

cd /etc

chmod 755 rc.local

1.5关闭防火墙

停止firewall

systemctl stop firewalld.service

禁止firewall开机启动

systemctl disable firewalld.service

 

猜你喜欢

转载自blog.csdn.net/houxian1103/article/details/109238468