1、配置支持包(下载地址)
nginx程序源代码:nginx-1.11.3.tar.gz
信息输出:echo-nginx-module-0.59.tar.gz
缓存清除:ngx_cache_purge-2.3.tar.gz
负载均衡:nginx_upstream-fair-a18b409.tar.gz
2、定义nginx编译输出目录
mkdir -p /usr/local/nginx/{logs,conf,fastcgi_temp,sbin,client_body_temp,proxy_temp,uwsgi_temp,scgi_temp}
3、将开发包上传到linux服务器之中
4、将开发包解压到"/usr/local/src"目录中
tar xzvf nginx-1.11.3.tar.gz -C /usr/local/src/
tar xzvf nginx-upstream-fair-a18b409.tar.gz -C /usr/local/src/
tar xzvf echo-nginx-module-0.59.tar.gz -C /usr/local/src/
tar xzvf ngx_cache_purge-2.3.tar.gz -C /usr/local/src/
5、nginx编译完成之后,会默认保存在源代码的目录之中,这样的操作不方便进行管理,所以可以单独建立一个新的文件目录,保存所有nginx的所有相关配置,目录名称/usr/local/nginx
mkdir -p /usr/local/nginx/{logs,conf,fastcgi_temp,sbin,client_body_temp,proxy_temp,uwsgi_temp,scgi_temp}
6、进入nginx源代码目录
cd /usr/local/src/nginx-1.11.3
7、安全所需插件
- ubuntu需要安装openSSL
sudo apt-get install openssl
sudo apt-get install libssl-dev
centos需要安装所需插件
yum install -y gcc pcre pcre-devel openssl openssl-devel gd gd-deve
8、编译Nginx源代码
./configure --prefix=/usr/local/nginx/--with-http_ssl_module\
--sbin-path=/usr/local/nginx/sbin/\
--with-http_ssl_module\
--conf-path=/usr/local/nginx/conf/nginx.conf\
--pid-path=/usr/local/nginx/logs/nginx.pid\
--error-log-path=/usr/local/nginx/logs/error.log\
--http-log-path=/usr/local/nginx/logs/access.log\
--http-fastcgi-temp-path=/usr/local/nginx/fastcgi_temp\
--http-client-body-temp-path=/usr/local/nginx/client_body_temp\
--http-proxy-temp-path=/usr/local/nginx/proxy_temp\
--http-uwsgi-temp-path=/usr/local/nginx/uwsgi_temp\
--http-scgi-temp-path=/usr/local/nginx/scgi_temp\
--add-module=/usr/local/src/echo-nginx-module-0.59\
--add-module=/usr/local/src/gnosek-nginx-upstream-fair-a18b409\
--add-module=/usr/local/src/ngx_cache_purge-2.3
9、安装Nginx
make && make install
10、启动Nginx
cd /usr/local/nginx/sbin
./nginx
11、查看是否启动成功
ps -ef | grep nginx
12、使用指定配置文件启动Nginx
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
13、设置防火墙放行端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload