环境:CentOS Linux release 7.3.1611 (Core) Linux localhost.localdomain 3.10.0-514.26.2.el7.x86_64 #1 SMP Tue Jul 4 15:04:05 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
一. 依赖包安装
yum -y install gcc automake autoconf libtool make gcc gcc-c++
二. 下载相关软件包到/usr/local/src/ 目录下并安装
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.gz
# 依赖pcre库是因为nginx的rewrite重写需要
wget https://zlib.net/fossils/zlib-1.2.11.tar.gz
#安装zlib库是因为gzip 模块需要
wget https://www.openssl.org/source/openssl-1.0.1t.tar.gz
#安装opensssl库是因为nginx的ssl服务依赖,安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议。
wget http://nginx.org/download/nginx-1.13.4.tar.gz
#nginx新版本的包 (稳定版)
cd pcre-8.38
./configure
make && make install
cd ..
#pcre库编译安装
cd openssl-1.0.1t
./configure
make && make install
cd ..
##openssl编译安装
cd zlib-1.2.11
./configure
make && make install
cd ..
#zlib库编译安装
cd nginx-1.13.4
./configure --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.38 --with-zlib=/usr/local/src/zlib-1.2.11 --with-openssl=/usr/local/src/openssl-1.0.1t
make && make install
#nginx编译安装
/*
注意如果make报错或者./configure报错应该是少了上面的依赖库,
或者你本机的依赖库版本问题,请安装较新的库。
*/
安装完成后配置文件如下:
[root@localhost nginx-1.13.4]# ll /usr/local/nginx/
total 8084
-rw-r--r-- 1 root root 1077 Aug 14 23:02 fastcgi.conf
-rw-r--r-- 1 root root 1077 Aug 14 23:02 fastcgi.conf.default
-rw-r--r-- 1 root root 1007 Aug 14 23:02 fastcgi_params
-rw-r--r-- 1 root root 1007 Aug 14 23:02 fastcgi_params.default
drwxr-xr-x 2 root root 40 Aug 14 23:02 html
-rw-r--r-- 1 root root 2837 Aug 14 23:02 koi-utf
-rw-r--r-- 1 root root 2223 Aug 14 23:02 koi-win
drwxr-xr-x 2 root root 6 Aug 14 23:02 logs
-rw-r--r-- 1 root root 3957 Aug 14 23:02 mime.types
-rw-r--r-- 1 root root 3957 Aug 14 23:02 mime.types.default
-rwxr-xr-x 1 root root 8215208 Aug 14 23:02 nginx
-rw-r--r-- 1 root root 2656 Aug 14 23:02 nginx.conf
-rw-r--r-- 1 root root 2656 Aug 14 23:02 nginx.conf.default
-rw-r--r-- 1 root root 636 Aug 14 23:02 scgi_params
-rw-r--r-- 1 root root 636 Aug 14 23:02 scgi_params.default
-rw-r--r-- 1 root root 664 Aug 14 23:02 uwsgi_params
-rw-r--r-- 1 root root 664 Aug 14 23:02 uwsgi_params.default
-rw-r--r-- 1 root root 3610 Aug 14 23:02 win-utf
[root@localhost nginx-1.13.4]#
我习惯把默认配置文件放到etc下,不更改也一样。
[root@localhost nginx]# cd /usr/local/nginx/
[root@localhost nginx]# mkdir /etc/nginx
[root@localhost nginx]# cp * /etc/nginx/
三.启动Nginx 并测试
[root@localhost nginx]# /usr/local/nginx/nginx -c /etc/nginx/nginx.conf
[root@localhost nginx]# ps -ef|grep nginx
root 52723 1 0 23:13 ? 00:00:00 nginx: master process /usr/local/nginx/nginx -c /etc/nginx/nginx.conf
nobody 52724 52723 0 23:13 ? 00:00:00 nginx: worker process
root 52726 19602 0 23:13 pts/0 00:00:00 grep --color=auto nginx
[root@localhost nginx]#
测试之前请关闭centos7的防火墙,这个防火墙真的很烦,限制了很多东西。。
[root@localhost nginx]# systemctl stop firewalld.service
[root@localhost nginx]# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
[root@localhost nginx]#
输入ip访问~