CentOs安装Nginx

安装 gcc pcre pcre-devel zlib OpenSSL 安装 安装 nginx 需要先将官网下载的源码进行编译,编译依赖 gcc 环境,如果没有 gcc 环境,则需要安装:

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

直接下载.tar.gz安装包,地址:https://nginx.org/en/download.html

使用wget命令下载(推荐)。确保系统已经安装了wget,如果没有安装,执行 yum install wget 安装。

wget -c https://nginx.org/download/nginx-1.12.0.tar.gz

我下载的是1.12.0版本,这个是目前的稳定版。

依然是直接命令:

tar -zxvf nginx-1.12.0.tar.gz
cd nginx-1.12.0

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

./configure

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

./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目录

make
make install

查找安装路径:

whereis nginx
cd /usr/local/nginx/sbin/
./nginx 
./nginx -s stop
./nginx -s quit
./nginx -s reload

查询nginx进程:

ps aux|grep nginx

1.先停止再启动(推荐): 对 nginx 进行重启相当于先停止再启动,即先执行停止命令再执行启动命令。如下:

./nginx -s quit
./nginx

2.重新加载配置文件: 当 ngin x的配置文件 nginx.conf 修改后,要想让配置生效需要重启 nginx,使用-s reload不用先停止 ngin x再启动 nginx 即可将配置信息在 nginx 中生效,如下: ./nginx -s reload

*firewall*-*cmd* --*zone=public* --*add*-*port=80/tcp* --*permanent*

即在rc.local增加启动代码就可以了。

vi /etc/rc.local
<h1 id="&#x589E;&#x52A0;&#x4E00;&#x884C;">&#x589E;&#x52A0;&#x4E00;&#x884C;&#xA0;</h1>

/usr/local/nginx/sbin/nginx

设置执行权限:

chmod&#xA0;755&#xA0;/etc/rc.local

Original: https://www.cnblogs.com/blogof-fusu/p/16468895.html
Author: 山有扶苏QWQ
Title: CentOs安装Nginx

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/683713/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球