centos7.6安装nginx

系统基础环境:virtualbox下CentOS-Minimal-1810

1安装方法一:源码编译安装

基础环境 centos7.6 mini

目录:/usr/local/src

1、安装前准备(根据各软件最新版本信息更改url)

下载nginx、openssl、zlib、pcre

 

cd /usr/local/src

wget http://nginx.org/download/nginx-1.10.2.tar.gz
wget http://www.openssl.org/source/openssl-fips-2.0.10.tar.gz
wget http://zlib.net/zlib-1.2.11.tar.gz
wget https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz

2安装(顺序不要错)

安装make

 

yum -y install gcc automake autoconf libtool make

安装gcc编译环境

 

# yum install gcc-c++

安装pcre

 

# tar zxvf pcre-8.43.tar.gz

# cd pcre-8.40

# ./configure && make && make install

安装openssl:

 

tar zxvf openssl-fips-2.0.10.tar.gz
cd openssl-fips-2.0.10
 ./config && make && make install

安装zlib

 

tar zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure && make && make install

安装nginx

 

tar zxvf nginx-1.10.2.tar.gz

cd nginx-1.10.2

./configure && make && make install

这样安装完成后,nginx的路径为/usr/local/nginx/sbin/nginx

2安装方法二:

查看CentOS的版本

 

cat /etc/redhat-release

添加资源库

在 CentOS 系统上安装 Nginx ,得先去添加一个资源库:

 

vim /etc/yum.repos.d/nginx.repo

  [nginx]

  name=nginx repo

  baseurl=http://nginx.org/packages/centos/$releasever/$basearch/

  gpgcheck=0

  enabled=1

安装nginx

 

yum -y install nginx

使用命令

 

systemctl stop nginx.service  #停止nginx服务
systemctl start nginx.service  #打开nginx服务
systemctl restart nginx.service  #重启nginx服务
systemctl status nginx.service  #查看nginx服务状态

验证nginx安装成果:

开启nginx,

 

cd /usr/local/nginx/sbin
./nginx
或
systemctl start nginx.service
验证:
curl http://localhost

应该能输出Welcome to nginx的html文件,说明安装启动成功。

开启外部访问

centos7默认开启了防火墙模块firewalld,可以查看一下是否开启

 

[root@localhost ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: active (running) since Mon 2019-03-18 10:12:46 EDT; 34s ago
     Docs: man:firewalld(1)
 Main PID: 3618 (firewalld)
   CGroup: /system.slice/firewalld.service
           └─3618 /usr/bin/python -Es /usr/sbin/firewalld --nofork...

Mar 18 10:12:46 localhost.localdomain systemd[1]: Starting firewal...
Mar 18 10:12:46 localhost.localdomain systemd[1]: Started firewall...
Hint: Some lines were ellipsized, use -l to show in full.

或者:

 

[root@localhost ~]# firewall-cmd --state
running

关闭firewalld,然后在虚拟机外可以访问

 

systemctl stop firewalld #关闭
systemctl start firewalld #打开
systemctl restart firewalld #重启
systemctl disable firewalld #关闭开机启动
systemctl enable firewalld #开机启动



作者:Gswu
链接:https://www.jianshu.com/p/24ebf5437a9e
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值