一、安装
1、ngnix官网(http://nginx.org/)下载.tart.gz格式的安装包
安装包:nginx-1.15.5.tar.gz
2、安装依赖包
由于nginx中的功能是模块化的,而模块化又依赖于一些软件包才能使用,因此在安装nginx之前要安装必要的软件包
常见软件包说明:
软件包 说明 pcre-devel 为nginx模块提供正则表达式库 zlib-devel 为nginx模块提供数据压缩用的函数库 openssl-devel 为nginx模块提供密码算法、证书以及SSL协议等 [root@localhost ~]# yum -y install pcre-devel zlib-devel openssl-devel
多学一招:devel包和非devel包的区别
非devel是一般普通的软件包,而devel包则一般会包括头文件、静态库甚至源码,若仅仅使用软件安装非devel包即可
3、ngnix的编译安装
(1)解压 nginx-1.15.5.tar.gz 安装包
[root@localhost ~]# tar -zxvf nginx-1.15.5.tar.gz
(2)切换到nginx解压目录
[root@localhost ~]# cd nginx-1.15.5
(3)配置nginx的编译选项,指定nginx的安装目录及安装模块
[root@localhost nginx-1.15.5]# ./configure \ --prefix=/usr/local/nginx \ --with-http_ssl_module
说明:
--prefix:指定软件安装目录
--with-http_ssl_module:安装了http_ssl_module模块相关功能
上面命令的中第一行和第二行 \ 斜杠是命令换行符
...... checking for PCRE JIT support ... found checking for zlib library ... found ...... Configuration summary + using system PCRE library + OpenSSL library is not used + using system zlib library nginx path prefix: "/usr/local/local/nginx" nginx binary file: "/usr/local/local/nginx/sbin/nginx" nginx modules path: "/usr/local/local/nginx/modules" nginx configuration prefix: "/usr/local/local/nginx/conf" nginx configuration file: "/usr/local/local/nginx/conf/nginx.conf" nginx pid file: "/usr/local/local/nginx/logs/nginx.pid" nginx error log file: "/usr/local/local/nginx/logs/error.log" nginx http access log file: "/usr/local/local/nginx/logs/access.log" nginx http client request body temporary files: "client_body_temp" nginx http proxy temporary files: "proxy_temp" nginx http fastcgi temporary files: "fastcgi_temp" nginx http uwsgi temporary files: "uwsgi_temp" nginx http scgi temporary files: "scgi_temp"
从./configure的输出中能看出nginx的安装后生产的文件及文件位置等
(4)通过make编译和安装
[root@localhost nginx-1.15.5]# make && make install
二、nginx启动和停止
1、启动nginx服务
[root@localhost ~]# cd /usr/local/nginx/sbin [root@localhost sbin]# ./nignx
2、停止nginx服务
(1)立即停止
[root@localhost sbin]# ./nignx -s stop
(2)从容停止(等待当前工作进程完成当前工作任务后再停止)
[root@localhost sbin]# ./nignx -s quit
(3)kill
[root@localhost ~]# kill -9 nginx主进程ID [root@localhost ~]# killall nginx
3、其他常用命令
命令 说明 nginx -s reload 重启 nginx -s reopen 打开日志文件 nginx -c /某个目录/nginx.conf 以某个nginx配置文件启动nginx服务 nginx -t 检测配置文件是否正确 nginx -t -c /某个目录/nginx.conf 检测某个nginx配置文件是否真确 nginx -v 显示版本信息 nginx -V 显示版本信息和编译选项
三、测试查看nignx是否启动成功
1、查看端口看nginx是否启动,nginx默认端口号为80
[root@localhost ~]# netstat -tuln
如果出现如下,代表启动nginx的80端口成功
2、通过ps -ef | grep nginx 查看 nginx 服务是否启动
[root@localhost ~]# ps -ef | grep nginx
3、浏览器输入nginx服务器的Ip地址查看,出现如下代表安装成功