nginx源码安装

nginx是一个使用广泛的高性能web服务器,下面简单介绍源码安装Nginx。
环境:

vm01    CentOS release 6.8      web01           192.168.1.211

源码安装nginx操作步骤:
1、下载nginx源码及安装模块需要的依赖包源码

[root@vm01 ~]# cd /usr/local/src/
[root@vm01 src]# wget http://nginx.org/download/nginx-1.12.0.tar.gz
[root@vm01 src]# wget https://ftp.pcre.org/pub/pcre/pcre-8.40.tar.gz
[root@vm01 src]# wget https://www.openssl.org/source/openssl-1.1.0e.tar.gz
[root@vm01 src]# tar zxf nginx-1.12.0.tar.gz 
[root@vm01 src]# tar zxf pcre-8.40.tar.gz 
[root@vm01 src]# tar zxf openssl-1.1.0e.tar.gz 
[root@vm01 src]# cd nginx-1.12.0
[root@vm01 nginx-1.12.0]# yum install gd-devel -y
[root@vm01 nginx-1.12.0]# ./configure --prefix=/usr/local/nginx \
    --with-http_stub_status_module \
    --with-http_ssl_module \
    --with-openssl=/usr/local/src/openssl-1.1.0e \
    --with-pcre=/usr/local/src/pcre-8.40 \
    --with-http_gzip_static_module \
    --with-http_realip_module \
    --with-http_image_filter_module 
[root@vm01 nginx-1.12.0]# make -j `grep -c processor /proc/cpuinfo`
[root@vm01 nginx-1.12.0]# make install
[root@vm01 nginx-1.12.0]# ln -s /usr/local/nginx/sbin/nginx /usr/bin/

ps:
另外也可以选择安装另一个高性能的nginx(OpenResty 它是一个基于Nginx的核心Web应用程序服务器,它包含了大量的第三方的Nginx模块和大部分系统依赖包。 OpenResty不是Nginx的分支,它只是一个软件包)
简单说下安装步骤:

安装依赖:yum install readline-devel pcre-devel openssl-devel
下载OpenResty
wget http://openresty.org/download/ngx_openresty-1.5.8.1.tar.gz.
解压、编译、安装:
tar xzvf ngx_openresty-1.5.8.1.tar.gz
cd ngx_openresty-1.5.8.1/
./configure --with-luajit --with-http_iconv_module  --with-http_postgres_module  -j2
make && make install

2、修改nginx配置文件 /usr/local/nginx/conf/nginx.conf

[root@vm01 nginx]# vim /usr/local/nginx/conf/nginx.conf
user nobody;
# nginx 1.9版本后 以下可使用auto
worker_processes auto;
worker_cpu_affinity auto;
****省略若干行****
events {
    use epoll;  # 指定使用epoll模型,事件驱动异步IO模型
    worker_connections  10240;
}
****省略若干行****

3、测试配置文件

[root@vm01 nginx]# /usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
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

4、启动Nginx

[root@vm01 nginx]# /usr/local/nginx/sbin/nginx  -c /usr/local/nginx/conf/nginx.conf  
[root@vm01 nginx]# ps -ef|grep nginx
root     26043     1  0 09:44 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody   26044 26043  0 09:44 ?        00:00:00 nginx: worker process                   
nobody   26045 26043  0 09:44 ?        00:00:00 nginx: worker process                   
nobody   26046 26043  0 09:44 ?        00:00:00 nginx: worker process                   
nobody   26048 26043  0 09:44 ?        00:00:00 nginx: worker process  

5、设置nginx开机启动

[root@vm01 nginx]# echo /usr/local/nginx/sbin/nginx  -c /usr/local/nginx/conf/nginx.conf  >>/etc/rc.local 

6、关闭nginx

[root@vm01 nginx]# nginx -s stop   # 快速关闭
或
[root@vm01 nginx]# nginx -s quit    # 安全关闭

7、访问测试
nginx开启后,浏览器中访问nginx默认首页 http://192.168.1.211

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值