nginx安装-源码编译

官方文档:http://nginx.org/en/docs/configure.html

参考:http://jingyan.baidu.com/article/e2284b2b45f693e2e6118de5.html

升级参考:http://urchin.blog.51cto.com/4356076/988860/  

         http://www.cnblogs.com/terrysun/archive/2012/11/22/2782472.html

编译源码需要的组件

1.zlib  http://www.zlib.net/

2.pcre http://www.pcre.org/            正则表达式

3.openssl  http://www.openssl.org/  可选

4.nginx     http://nginx.org/en/download.html

 ---------------------------------------------------------------- 

1.编译zlib (version 1.1.3 — 1.2.8)

mkdir /usr/src/zlib 
cd /usr/src/zlib
wget  http://zlib.net/zlib-1.2.8.tar.gz
tar xvf zlib-1.2.8.tar.gz

cd /usr/src/zlib/zlib-1.2.8
./configure --static --prefix=/usr/src/zlib/zlib-1.2.8 make make install

2.编译openssl 

 直接使用apt-get进行安装 
sudo apt-get install openssl
sudo apt-get install libssl-dev

3.编译pcre (version 4.4 — 8.38)

mkdir /usr/src/pcre
wget  ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.gz
tar xvf pcre2-8.38.tar.gz
/configure --prefix=/usr/src/pcre/pcre-8.38

make install

4.编译ngnix

复制代码
mkdir /usr/src/nginx
cd /usr/src/nginx
wget http://nginx.org/download/nginx-1.9.14.tar.gz
tar xvf nginx-1.9.14.tar.gz
mv nginx-1.9.14 nginx
./configure --prefix=/usr/local/nginx/  --conf-path=/usr/local/nginx/nginx.conf --sbin-path=/usr/local/nginx/sbin/nginx --with-debug --with-openssl=/usr/src/openssl/openssl-1.0.2g --with-zlib=/usr/src/zlib/zlib-1.2.8 --with-pcre=/usr/src/pcre/pcre-8.38 --with-http_stub_status_module --with-http_gzip_static_module 
  
make install
复制代码

生成的nginx在/usr/local/nginx/sbin下

./nginx -v 检测是否安装成功
./nginx 启动
在地址栏输入: http://localhost 如果看到以下效果,说明正确安装了

转载于:https://www.cnblogs.com/zjxbetter/p/5387485.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1. 下载nginx码 首先,我们需要从nginx官网下载最新版本的nginx码,下载地址:http://nginx.org/en/download.html 2. 安装依赖 在编译安装nginx之前,需要安装一些依赖库,如gcc、pcre、openssl、zlib等。 可以使用以下命令安装这些依赖: ``` sudo apt-get update sudo apt-get install gcc sudo apt-get install libpcre3 libpcre3-dev sudo apt-get install libssl-dev sudo apt-get install zlib1g-dev ``` 3. 解压码 将下载好的nginx码包解压到指定目录中,如: ``` tar -zxvf nginx-1.16.1.tar.gz ``` 4. 配置编译选项 进入解压后的nginx码目录,执行以下命令进行配置: ``` ./configure --prefix=/usr/local/nginx \ --with-http_ssl_module \ --with-http_stub_status_module \ --with-http_gzip_static_module \ --with-pcre \ --with-stream \ --with-stream_ssl_module \ --with-http_realip_module \ --with-http_v2_module ``` 上述命令中,各选项的含义如下: --prefix:指定nginx安装目录。 --with-http_ssl_module:启用SSL支持。 --with-http_stub_status_module:启用stub_status模块,用于显示nginx的状态信息。 --with-http_gzip_static_module:启用gzip_static模块,用于预压缩静态文件。 --with-pcre:启用PCRE库,用于正则表达式匹配功能。 --with-stream:启用stream模块,用于TCP/UDP流量控制。 --with-stream_ssl_module:启用stream模块的SSL支持。 --with-http_realip_module:启用realip模块,用于获取真实客户端IP。 --with-http_v2_module:启用HTTP/2协议支持。 5. 编译安装 配置完成后,执行以下命令进行编译安装: ``` make sudo make install ``` 6. 启动nginx服务 安装完成后,可以使用以下命令启动nginx服务: ``` sudo /usr/local/nginx/sbin/nginx ``` 7. 检查nginx是否启动成功 可以在浏览器中输入 http://localhost,如果出现"Welcome to nginx!"的页面,则表示nginx已经成功安装和启动。 至此,nginx编译安装完成。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值