Nginx (“engine x”) 是一个高性能HTTP 和 反向代理 服务器、IMAP、POP3、SMTP 服务器。
本文主要写Nginx的源码安装,所以这里具体原理不写,(如有需求可至nginx官网http://nginx.org/查看)
系统环境:Centos 7.X
Nginx版本 :1.12.0 (其他版本安装方法一样)
1.安装Nginx
#关闭防火墙和selinux
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
#安装PCRE库支持和后续用到的一些命令和依赖包
[root@localhost ~]# yum install pcre pcre-devel wget gcc-c++ openssl openssl-devel -y
#创建一个存放源码包的文件,进入文件中
[root@localhost ~]# mkdir /tools
[root@localhost ~]# cd /tools/
[root@localhost tools]#
#下载Nginx源码包
[root@localhost tools]# wget -c http://nginx.org/download/nginx-1.12.0.tar.gz
#解压Nginx源码包
[root@localhost tools]# ls
nginx-1.12.0.tar.gz
[root@localhost tools]# tar zxf nginx-1.12.0.tar.gz
[root@localhost tools]# ls
nginx-1.12.0 nginx-1.12.0.tar.gz
[root@localhost tools]# cd nginx-1.12.0
[root@localhost nginx-1.12.0]#
#预编译Nginx
[root@localhost nginx-1.12.0]# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
#.configure预编译成功后,执行make命令进行编译
[root@localhost nginx-1.12.0]# make
#make执行成功后,执行make install 正式安装
[root@localhost nginx-1.12.0]# make install
#至此Nginx Web 安装完成
2.启动Nginx
#检查nginx配置文件是否正确,如下返回OK和successful即正确。
[root@localhost nginx-1.12.0]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
#启动nginx
[root@localhost nginx-1.12.0]# /usr/local/nginx/sbin/nginx
#查看nginx进程是否已启动(下列情况表示nginx进程存在,启动是成功的)
[root@localhost nginx-1.12.0]# ps -ef|grep nginx
root 6251 1 0 08:19 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody 6252 6251 0 08:19 ? 00:00:00 nginx: worker process
root 6256 1094 0 08:22 pts/0 00:00:00 grep --color=auto nginx
3.测试Nginx
通过浏览器访问本机IP 地址,会出现nginx默认页面,如下图
到此nginx已经安装成功,这只是安装,如需使用还需更一步了解。
故乡容不下肉身,他乡容不下灵魂,若能一世安稳,谁愿颠沛流离!!
前路浩浩荡荡,万事尽可期待~~