Nginx安装环境
Nginx 是 C 语言开发的,本教程使用Centos7.0作为安装环境.
环境准备:
- gcc:
yum install gcc-c++
(作用:依赖gcc编译官网下载的源码) - PCRE:
yum install -y pcre pcre-devel
(作用:nginx 的 http 模块使用 pcre 来解析正则表达式)
PCRE(Perl Compatible Regular Expressions)是一个 Perl 库,包括 perl 兼容的正则表达式库
- zlib:
yum install -y zlib zlib-devel
(nginx 使用 zlib 对 http 包的内容进行 gzip 压缩,而 zlib 库提供了很多种压缩和解压缩的方式) - OpenSSL:
yum install -y openssl openssl-devel
(作用:nginx 不仅支持 http 协议,还支持 https(即在 ssl 协议上传输 http),所以需要在linux 安装 openssl 库。)
OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用。
最近要配置 HTTPS 才发现安装时没有安装 ssl 模块,百度了一下解决方案,记录如下:
解决方案:编译安装的时候带上–with-http_ssl_module配置即可。
下面是详细步骤:
我的环境:
- 安装目录 /usr/local/nginx
- 源码目录 /usr/local/nginx-1.8.0
1. 编译
切换到源码包,进行编译
[root@iZ8vb7en797f7sdjs8f28mZ ~]# cd /usr/local/nginx-1.8.0/
然后配置如下:
./configure \
--prefix=/usr/local/nginx \
--with-http_stub_status_module \
--with-http_ssl_module \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi
[root@iZ8vb7en797f7sdjs8f28mZ nginx-1.8.0]# make
2. make install
[root@iZ8vb7en797f7sdjs8f28mZ sbin]# cd /usr/local/nginx-1.8.0
[root@iZ8vb7en797f7sdjs8f28mZ nginx-1.8.0]# ls
auto CHANGES CHANGES.ru conf configure contrib html LICENSE Makefile man objs README src
[root@iZ8vb7en797f7sdjs8f28mZ nginx-1.8.0]# make install
4. 启动Nginx
[root@iZ8vb7en797f7sdjs8f28mZ nginx-1.8.0]# cd sbin
[root@iZ8vb7en797f7sdjs8f28mZ sbin]# ./nginx
nginx: [emerg] mkdir() "/var/temp/nginx/client" failed (2: No such file or directory)
[root@localhost sbin]# mkdir -p /var/temp/nginx/client
[root@localhost sbin]# ./nginx
[root@localhost sbin]# ps -ef | grep nginx
root 21126 1 0 10:29 ? 00:00:00 nginx: master process ./nginx
nobody 21127 21126 0 10:29 ? 00:00:00 nginx: worker process
root 21129 15180 0 10:29 pts/0 00:00:00 grep --color=auto nginx
[root@iZ8vb7en797f7sdjs8f28mZ sbin]# ./nginx -V
nginx version: nginx/1.8.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC)
configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_gzip_static_module --http-client-body-temp-path=/var/temp/nginx/client --http-proxy-temp-path=/var/temp/nginx/proxy --http-fastcgi-temp-path=/var/temp/nginx/fastcgi --http-uwsgi-temp-path=/var/temp/nginx/uwsgi --http-scgi-temp-path=/var/temp/nginx/scgi
其他:查看安装配置
切换到 Nginx的安装目录,执行 ./nginx -V
[root@iZ8vb7en797f7sdjs8f28mZ nginx-1.8.0]# cd /usr/local/nginx/sbin
[root@iZ8vb7en797f7sdjs8f28mZ sbin]# ls
nginx
[root@iZ8vb7en797f7sdjs8f28mZ sbin]# ./nginx -V
nginx version: nginx/1.8.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC)
configure arguments: --prefix=/usr/local/nginx --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_gzip_static_module --http-client-body-temp-path=/var/temp/nginx/client --http-proxy-temp-path=/var/temp/nginx/proxy --http-fastcgi-temp-path=/var/temp/nginx/fastcgi --http-uwsgi-temp-path=/var/temp/nginx/uwsgi --http-scgi-temp-path=/var/temp/nginx/scgi
[root@iZ8vb7en797f7sdjs8f28mZ sbin]#