当前位置:首页 - Linux

Centos 安装 Nginx

作者:高景洋 日期:2020-07-14 00:12:13 浏览次数:1710

1、长话短说,依次执行以下命令

    yum install gcc-c++
    yum install -y pcre pcre-devel
    yum install -y zlib zlib-devel
    yum install -y openssl openssl-devel


2、直接下载.tar.gz安装包

    地址:https://nginx.org/en/download.html 选 Stable version 中间的 链接

     可以通过 wget -c https://nginx.org/download/nginx-1.12.0.tar.gz

    或者先下载到本地,然后用 Put 上传到服务器

3、对压缩包解压 


    tar -zxvf nginx-1.18.0.tar.gz 
 cd nginx-1.18.0
4、配置nginx 



     其实在 nginx-1.12.0 以后版本中你就不需要去配置相关东西,默认就可以了。当然,如果你要自己配置目录也是可以的。


    1.使用默认配置

   ./configure

    2.如果nginx 需要支持https 

    ./configure --prefix=/usr/local/nginx --with-http_ssl_module

    3.自定义配置(不推荐)

   ./configure \
   --prefix=/usr/local/nginx \
   --conf-path=/usr/local/nginx/conf/nginx.conf \
   --pid-path=/usr/local/nginx/conf/nginx.pid \
   --lock-path=/var/lock/nginx.lock \
   --error-log-path=/var/log/nginx/error.log \
   --http-log-path=/var/log/nginx/access.log \
   --with-http_gzip_static_module \
   --http-client-body-temp-path=/var/temp/nginx/client \
   --http-proxy-temp-path=/var/temp/nginx/proxy \
   --http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
   --http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
   --http-scgi-temp-path=/var/temp/nginx/scgi
 
 注:将临时文件目录指定为/var/temp/nginx,需要在/var下创建temp及nginx目录
5、编译安装
 
 make 
 make install
5.1 执行 :/usr/local/nginx/sbin/nginx -V
 如果提示:configure arguments: --prefix=/usr/local/nginx --with-http_ssl_module
    则表示 nginx 已支持https
6、启停nginx

cd /usr/local/nginx/sbin/

 ./nginx 
  ./nginx -s stop
  ./nginx -s quit
  ./nginx -s reload





本文永久性链接:
<a href="http://r4.com.cn/art137.aspx">Centos 安装 Nginx</a>
当前header:Host: r4.com.cn X-Host1: r4.com.cn X-Host2: r4.com.cn X-Host3: 127.0.0.1:8080 X-Forwarded-For: 18.117.153.38 X-Real-Ip: 18.117.153.38 X-Domain: r4.com.cn X-Request: GET /art137.aspx HTTP/1.1 X-Request-Uri: /art137.aspx Connection: close Accept: */* User-Agent: Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com) Referer: http://www.yuezhiji.net/art137.aspx