首先开放防火墙端口或者关闭防火墙:
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
sed -i 's/SELINUX=enforcing/SELINUX=disabled /' /etc/selinux/config
#关闭防火墙:
systemctl disable firewalld.service
#重启使生效:
shutdown -r now
配置yum源,epel-7.源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum clean all # 清除系统所有的yum缓存
yum makecache # 生成yum缓存
yum install -y epel-release ### 安装 epel 用于下载第三方的软件
#安装Nginx
[root@localhost ~]# yum install nginx.x86_64 -y
启动 Nginx
Nginx 启动命令如下:
systemctl start nginx #启动Nginx
systemctl stop nginx #停止Nginx
systemctl restart nginx #重启Nginx
Nginx二进制编译安装配置
开放防火墙端口:
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
sed -i 's/SELINUX=enforcing/SELINUX=disabled /' /etc/selinux/config
#关闭防火墙:
systemctl disable firewalld.service
#重启使生效:
shutdown -r now
Nginx 安装编译工具及库文件
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
先要安装 PCRE
PCRE 作用是让 Nginx 支持 Rewrite 功能。
1、下载 PCRE 安装包,下载地址: http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
[root@localhost /]# cd /usr/local/src/
[root@bogon src]# wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
2、解压安装包:
[root@bogon src]# tar zxvf pcre-8.35.tar.gz
3、进入安装包目录
[root@bogon src]# cd pcre-8.35
4、编译安装
[root@bogon pcre-8.35]# ./configure
[root@bogon pcre-8.35]# make && make install
5、查看pcre版本
[root@bogon pcre-8.35]# pcre-config --version
安装 Nginx
1、下载 Nginx,下载地址:http://nginx.org/download/nginx-1.19.10.tar.gz
[root@bogon src]# cd /usr/local/src/
[root@bogon src]# wget http://nginx.org/download/nginx-1.19.10.tar.gz
2,解压包
[root@localhost src]# tar zxvf nginx-1.19.10.tar.gz
3、进入安装包目录
[root@localhost src]# cd nginx-1.19.10/
4、编译安装
[root@localhost nginx-1.19.10]# ./configure --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.35
[root@localhost nginx-1.19.10]# make
[root@localhost nginx-1.19.10]# make install
5、查看nginx版本
[root@localhost nginx-1.19.10]# /usr/local/webserver/nginx/sbin/nginx -v
6,配置nginx.conf
[root@localhost ~]# vim /usr/local/webserver/nginx/conf/nginx.conf
更改 这两处
server_name www.test.com; #域名
root /usr/local/webserver/nginx/html; #站点目录
[root@localhost ~]# cd /usr/local/webserver/nginx/html
[root@localhost html]# cp index.html index.html.bak
[root@localhost html]# vim index.html
[root@localhost html]# cat index.html
<h1>Welcome to nginx!</h1>
启动 Nginx
Nginx 启动命令如下:
[root@localhost /]# /usr/local/webserver/nginx/sbin/nginx
[root@localhost /]# /usr/local/webserver/nginx/sbin/nginx -s reload # 重新载入配置文件
[root@localhost /]# /usr/local/webserver/nginx/sbin/nginx -s reopen # 重启 Nginx
[root@localhost /]# /usr/local/webserver/nginx/sbin/nginx -s stop # 停止 Nginx
测试
curl 192.168.100.20
注:如果在虚拟机下配置好在浏览器下访问不了,操作如下就好了
host文件的位置 添加域名和IP地址
C:\Windows\System32\drivers\etc 目录下的hosts 文件打开添加
192.168.100.20 www.test.com