一聚教程网:一个值得你收藏的教程网站

热门教程

nginx安装到指定目录的教程

时间:2022-06-30 18:20:02 编辑:袖梨 来源:一聚教程网

公司需求,需要在同一台机器上装两个不同位置的 nginx。what!我之前都是直接装在 /user/local/ 下的啊, 或者 yum install nginx 装在 /etc/nginx 啊,这怎么办

经过我的一番寻找终于看到的一些靠谱的答案。   

./configure 
--prefix=你想要安装的目录 
--sbin-path=/你想要安装的目录/nginx 
--conf-path=/你想要安装的目录/nginx.conf 
--pid-path=/你想要安装的目录/nginx.pid 
--with-http_ssl_module 
--with-pcre=/usr/local/pcre-8.38 
--with-zlib=/usr/local/zlib-1.2.11 
--with-openssl=/usr/local/openssl-1.0.1t  

make && make install 

test -d

我的理解

这是源码编译安装 ngixn,./configure 这一步是给 nginx 设置一些常量。而 --prefix 则是设置编译后到处 nginx 执行文件的地址。

现在网上虽然也有些教程但是也有很多已经老了,有些包找不到了。那我就把我这此安装的步骤分享出来

nginx 安装到自定义位置

先安装 pcre

  cd /usr/local/
  # 下载
  wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.gz
  # 解压
  tar -zxvf pcre-8.38.tar.gz

  cd pcre-8.38

  ./configure
  # 编译
  make && make install

  # 记住这个安装目录一会儿会用到
  # /usr/local/pcre-8.38

其次是 zlib

  cd /usr/local/
  # 下载
  wget http://www.zlib.net/zlib-1.2.11.tar.gz
  # 解压
  tar -zxvf zlib-1.2.11.tar.gz

  cd zlib-1.2.11
  
  ./configure
  # 编译
  make && make install

  # 记住这个安装目录一会儿会用到
  # /usr/local/zlib-1.2.11

ssl 这个不用编译,简单

  cd /usr/local/
  wget https://www.openssl.org/source/openssl-1.0.1t.tar.gz
  tar -zxvf openssl-1.0.1t.tar.gz
  
  # 记住这个安装目录一会儿会用到
  # /usr/local/openssl-1.0.1t

现在安装 Nginx

  cd /usr/local
  #下载解压
  wget http://nginx.org/download/nginx-1.4.2.tar.gz
  tar -zxvf nginx-1.4.2.tar.gz
  # 注意:这只是源码
  cd nginx-1.4.2

  # 设置常量

  ./configure 
  --prefix=/自定义位置/ 
  --sbin-path=/自定义位置/nginx 
  --conf-path=/自定义位置/nginx.conf 
  --pid-path=/自定义位置/nginx.pid 
  --with-http_ssl_module 
  --with-pcre=/usr/local/pcre-8.38      # 刚刚安装的 pcre 的位置
  --with-zlib=/usr/local/zlib-1.2.11     # 刚刚安装的 zlib 的位置
  --with-openssl=/usr/local/openssl-1.0.1t  #刚刚安装的 openssl 的位置

  # 编译
  make && make install

  # 重要:如果不执行则不会创建真正的 nginx 文件
  test -d

热门栏目