Linux学习记录-Centos 8 安装 Nginx

安装步骤:

1. 安装编译工具及库文件

yum -y install gcc gcc-c++ automake autoconf libtool make

2. 安装PCRE

注意:pcre 必须是最新版的 

PCRE 作用是让 Nginx 支持 Rewrite 功能。

cd /usr/local/src &&
wget http://downloads.sourceforge.net/project/pcre/pcre/8.43/pcre-8.43.tar.gz &&
tar -zxvf pcre-8.43.tar.gz &&
cd pcre-8.43 &&
./configure &&
make &&
make install &&
pcre-config --version

3. 安装zlib库

cd /usr/local/src &&
wget http://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

4. 安装OpenSSL

cd /usr/local/src &&
wget https://www.openssl.org/source/openssl-1.0.2t.tar.gz &&
tar -zxvf openssl-1.0.2t.tar.gz

5. 安装Nginx

cd /usr/local/src &&
wget http://nginx.org/download/nginx-1.17.6.tar.gz &&
tar -zxvf nginx-1.17.6.tar.gz &&
cd nginx-1.17.6 &&
./configure --sbin-path=/usr/local/nginx/nginx \
--conf-path=/usr/local/nginx/nginx.conf \
--pid-path=/usr/local/nginx/nginx.pid \
--with-http_ssl_module \
--with-pcre=/usr/local/src/pcre-8.43 \
--with-zlib=/usr/local/src/zlib-1.2.11 \
--with-openssl=/usr/local/src/openssl-1.0.2t &&
make &&
make install

6. 查看是否安装成功

[mico@localhost /]$ cd  /usr/local/nginx 
[mico@localhost nginx]$ ls
client_body_temp      fastcgi_params          html     logs                nginx               nginx.pid    scgi_params.default  uwsgi_params.default
fastcgi.conf          fastcgi_params.default  koi-utf  mime.types          nginx.conf          proxy_temp   scgi_temp            uwsgi_temp
fastcgi.conf.default  fastcgi_temp            koi-win  mime.types.default  nginx.conf.default  scgi_params  uwsgi_params         win-utf
[mico@localhost nginx]$ 

7. 启动

确保系统的 80 端口没被其他程序占用,运行/usr/local/nginx/nginx 命令来启动 Nginx

netstat -ano|grep 80

如果查不到结果后执行,有结果则忽略此步骤(ubuntu下必须用sudo启动,不然只能在前台运行)

sudo /usr/local/nginx/nginx

8. 开放80端口 (目前Centos8的防火墙已经更改为firewalld,iptables已经不使用)
先查看防火墙状态 systemctl status firewalld
如果开启的情况下,则需要添加开放端

firewall-cmd --zone=public --add-port=80/tcp --permanent &&
systemctl restart firewalld.service

9. 验证是否安装成功

[mico@localhost nginx]$ curl http://localhost
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
[mico@localhost nginx]$ 

10. 可能用到的一些命令

/usr/local/nginx/nginx -s reload           # 重新载入配置文件
/usr/local/nginx/nginx -s reopen           # 重启 Nginx
/usr/local/nginx/nginx -s stop             # 停止 Nginx

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值