基于linux的nginx安装
Nginx安装
1 官网:www.nginx.org
1.3 下载nginx-1.16.1.tar.gz
[[email protected] ~]# wget http://nginx.org/download/nginx-1.16.1.tar.gz
1.4 解压nginx-1.16.1.tar.gz
[[email protected] ~]# tar -zxvf nginx-1.16.1.tar.gz
nginx目录
auto目录:存放大量的脚本文件,和configure脚本程序相关configure文件,Nginx自动安装脚本,用于检查环境,生成编译代码需要的makefile文件,
html目录:存放nginx的源代码
conf目录:存放nginx服务器的配置文件
1.5
1.6 nginx的编译安装
[[email protected] ~]# cd nginx-1.16.1
[[email protected] nginx-1.16.1]# ./configure
–prefix=/usr/local/nginx
–with-http_ssl_module
[[email protected] nginx-1.16.1]# make && make install
参数说明:
./configure用于对即将安装的软件进行配置,检查当前的环境是否满足安装软件(Nginx)的依赖关系
“–prefix”参数用于设置Nginx的安装目录,默认值“/usr/local/nginx”,可省略此参数或指定到其他位置
“–with-http_ssl_module”参数用于设置在Nginx中允许使用http_ssl_module模块的相关功能
2.1启动nginx
[[email protected] ~]# cd /usr/local/nginx/sbin
[[email protected] sbin]# ./nginx
[[email protected] ~]# ps aux | grep nginx
2.2访问测试前开放80端口
2.3查看端口占用
[[email protected] sbin]# netstat -tlnp
2.4开放80端口
[[email protected] sbin]# iptables -I INPUT -p tcp --dport 80 -j ACCEPT
2.5重启iptables服务
[[email protected] ~]# service iptables status
[[email protected] ~]# service iptables save
[[email protected] ~]# service iptables restart
2.6停止nginx服务
[[email protected] sbin]# ./nginx -s stop
立即停止,无论当前工作进程是否正在处理工作
参数“-s”表示发送信号到主进程
“stop”表示停止服务
[[email protected] sbin]# ./nginx -s quit
从容停止,是在完成当前工作任务后再停止
“quit”表示从容停止方式
方式一
[[email protected] ~]# kill Nginx主进程的PID
方式二
[[email protected] ~]# killall nginx
Linux中提供了kill和killall命令可以杀死进程,从而让指定进程停止运行。
添加到环境变量
echo$PATH
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/nginx
n用于创建链接参数“-s”表示创建软链接,类似Windows中的快捷方式,后面跟两个路径
第1个路径是源文件路径第2个路径是目标文件路径
创建软链接后,就可以在任意目录下直接使用nginx命令来控制Nginx服务。
停止Nginx服务
[[email protected] ~]# nginx –s quit
启动Nginx服务
[[email protected] ~]# nginx
重新载入配置
[[email protected] ~]# nginx –s reload