nginx编译安装

Nginx 安装

这里的安装以源码安装为主。且主要以Linux 系统上的安装为准

确保系统安装了 pcre 软件包,因为Nginx rewrite 模块要依赖此软件包

[root@dell710 Downloads]# yum -y install pcre pcre-devel

Nginx 的官网 http://nginx.org/download/, 下载源代码文件。

[root@dell710 Downloads]# wget http://nginx.org/download/nginx-1.9.9.tar.gz

[root@dell710 Downloads]# tar zxvf nginx-1.9.9.tar.gz

[root@dell710 Downloads]# cd nginx-1.9.9/

[root@dell710 nginx-1.9.9]# ./configure \

> --prefix=/usr/local/nginx \

> --without-select_module \

> --without-poll_module \

> --with-debug \

> --with-http_ssl_module \

> --with-http_realip_module \

> --with-http_addition_module \

> --with-http_sub_module \

> --with-http_dav_module \

> --with-http_flv_module \

> --with-http_xslt_module \

> --with-http_gzip_static_module \

> --with-http_random_index_module \

> --with-http_secure_link_module \

> --with-http_degradation_module \

> --with-http_stub_status_module \

> --with-cc=`which gcc`

报错1:

[root@dell710 nginx-1.9.9] ./configure: error: the HTTP XSLT module requires the libxml2/libxslt

libraries. You can either do not enable the module or install the libraries.

解决方法

[root@dell710 nginx-1.9.9]# yum -y install libxml2 libxml2-dev

[root@dell710 nginx-1.9.9]# yum -y install libxslt-devel

 

错误2:

[root@dell710 nginx-1.9.9]# make

make: *** No rule to make target `build', needed by `default'.  Stop.

解决方法

检查以下是否漏装,未安装,安装

[root@dell710 nginx-1.9.9]# yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-dev

删除旧的,重新./configure后make及正常


 

[root@dell710 nginx-1.9.9]# make

或者

[root@dell710 nginx-1.9.9]# make -j 4  
#加快编译速度, 有多少个CPU核心,就可以写多少,实际根据您的服务器自行处理。
[root@dell710 nginx-1.9.9]# make install

# 经过make install 之后, nginx 程序就被安装在了/usr/local/nginx 这个目录中。这也是我们在编译安装中--prefix=/usr/local/nginx指定的。实际生产环境按需求配置即可。
[root@dell710 nginx-1.9.9]# ls /usr/local/nginx/

conf  html  logs  sbin

Nginx 的启动、停止、升级

这里以上文中,Nginx 的安装目录为/usr/local/nginx 。若Nginx 被安装在其他目录中,请修正下文中操作nginx 的路径。

语法检测

[root@dell710 nginx-1.9.9]# /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@dell710 nginx-1.9.9]# /usr/local/nginx/sbin/nginx

nginx停止

[root@dell710 nginx-1.9.9]# /usr/local/nginx/sbin/nginx -s stop

nginx平滑重启

[root@dell710 nginx-1.9.9]# /usr/local/nginx/sbin/nginx -s reload

 

Nginx 的操作, 尽量不要使用相对路径。比如我们使用的相对路径启动,我们发现使用相对路径启动的Nginx 在进程信息里也是一个相对路径的形式。这个形式对运维特别不友好。若我们根本不知道Nginx 的安装路径,则没有办法对Nginx 做下一步操作。
 

[root@dell710 nginx-1.9.9]# /usr/local/nginx/sbin/nginx

[root@dell710 nginx-1.9.9]# ps -aux |grep nginx |grep -v grep

root     22265  0.0  0.0  63732  1260 ?        Ss   11:48   0:00 nginx: master process /usr/local/nginx/sbin/nginx

nobody   22266  0.0  0.0  66252  2392 ?        S    11:48   0:00 nginx: worker process


[root@dell710 nginx-1.9.9]# cd /usr/local/nginx/sbin/

[root@dell710 sbin]# ./nginx

[root@dell710 sbin]# ps -aux |grep nginx |grep -v grep

root     22562  0.0  0.0  63732  1256 ?        Ss   11:55   0:00 nginx: master process ./nginx

nobody   22563  0.0  0.0  66252  2144 ?        S    11:55   0:00 nginx: worker process

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值