1. 安装Nginx(源码编译安装,平台为rhel6.5.x86_64)
1.1下载源码包并解压(尽量选择稳定版本)
[root@lockey ~]# wget http://nginx.org/download/nginx-1.12.1.tar.gz
[root@lockey ~]# tar zxvf nginx-1.12.1.tar.gz
1.2 编译前的配置
编译安装nginx的时候为了安全起见需要在源代码文件中把版本号注释掉,这是为了防止针对特定版本的恶意攻击
[root@lockey ~]#vim /root/nginx-1.12.1/src/core/nginx.h
#define NGINX_VER "nginx/" // NGINX_VERSION
关闭编译时的调试模式,这样编译得到的源码包的大小会减少很多
[root@lockey ~]#cd /root/nginx-1.12.1/auto/cc
[root@lockey ~]#vim gcc
# debug
#CFLAGS="$CFLAGS -g"
配置
./configure --user=www --group=www --prefix=/usr/local/nginx --with-file-aio --with-threads --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module
参数解释:
#--prefix=/usr/local/nginx指定安装路径
#--with-http_stub_status_module开启Nginx自带状态检测模块
#--with-http_ssl_module开启https模块
#--with-file-aio 开启文件AIO支持
#--with-threads 启用线程池支持
配置过程中可能出现的问题以及解决:
缺少PCRE库的支持
解决:yum install pcre-devel -y
缺少openssl支持:
解决:yum install openssl-devel -y
1.3 编译和安装
[root@lockey nginx-1.12.1]# make && make install
1.4 服务的启动以及测试
注意:一般对配置文件/usr/local/nginx/conf/nginx.conf做了修改后需要首先运行以下命令检查配置是否有语法错误然后再进行服务的停启动作:
/usr/local/nginx/sbin/./nginx -t
服务启动方法一:/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
启动方法二:cd /usr/local/nginx/sbin && ./nginx
测试:在浏览器中输入http://ip:80能够看到Nginx的欢迎界面则基本的配置就算是成功了
关于服务的停止/usr/local/nginx