Nginx —— 1、安装

目录

1、配置虚拟机上网

 2、配置静态 IP

3、nginx 安装

4、启动

5、防火墙

6、安装成系统服务

7、设置开机启动


首先下载 VMware 并创建虚拟机,可以参考VMware16的安装及VMware配置Linux虚拟机(详解版)_何故M的博客-CSDN博客_vmware16虚拟机安装linux前言为了Linux系统初学者的学习,以及不必要再花费成本与时间去安装Linux系统,使用VMware下配置Linux虚拟机进行学习也是个不错的选择。次文详解了VMware16软件的安装步骤,以及Linux虚拟机的CentOS 7简易安装的步骤,操作简单,完全足够Linux系统初学者的学习。VMware软件下载地址:https://www.vmware.com/cn/products/workstation-pro/workstation-pro-evaluation.htmlCentOS 7 下载映像https://blog.csdn.net/m0_50519965/article/details/116175873?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522165105368516781683938263%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=165105368516781683938263&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~top_positive~default-1-116175873.142%5Ev9%5Epc_search_result_control_group,157%5Ev4%5Econtrol&utm_term=vmware&spm=1018.2226.3001.4187

1、配置虚拟机上网

修改配置网卡配置文件

vi /etc/sysconfig/network-scripts/ifcfg-ens33

修改 ONBOOT=yes

重启网络服务

systemctl restart network

测试

ping qq.com

 2、配置静态 IP

之前的网络配置是使用dhcp方式分配ip地址,这种方式会在系统每次联网的时候分配一个ip给我们用,也就是说有可
能系统下次启动的时候ip会变,这样非常不方便我们管理。

配置静态ip首先需要打开网卡配置文件

vi /etc/sysconfig/network-scripts/ifcfg-ens33

修改启动协议 BOOTPROTO=static,手动配置 IP

_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="static"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33"
UUID="86d32c4a-802c-42e0-8f71-b8400c9d3f88"
DEVICE="ens33"
ONBOOT="yes"
IPADDR=192.168.44.101
NETMASK=255.255.255.0
GATEWAY=192.168.44.2
DNS1=8.8.8.8
DNS2=8.8.8.4 

接下来重启网络服务

systemctl restart network

使用 ifconfig 查看

3、nginx 安装

先到要安装的文件夹下打开终端,然后下载压缩包

wget  http://nginx.org/download/nginx-1.21.6.tar.gz

解压

tar zxvf nginx-1.18.0.tar.gz

安装

./configure --prefix=/usr/local/nginx
make
make install

若安装时出现以下报错,需要安装其他插件

1、 

checking for OS 
+ Linux 3.10.0-693.el7.x86_64 x86_64 
checking for C compiler ... not found
 ./configure: error: C compiler cc is not found

安装gcc 

yum install -y gcc

2、

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module 
option, or install the PCRE library into the system, or build the PCRE library 
statically from the source with nginx by using --with-pcre=<path> option.

安装perl库

yum install -y pcre pcre-devel

3、

./configure: error: the HTTP gzip module requires the zlib library. 
You can either disable the module by using --without-http_gzip_module 
option, or install the zlib library into the system, or build the zlib library 
statically from the source with nginx by using --with-zlib=<path> option.

安装zlib库

yum install -y zlib zlib-devel

4、启动

进入安装好的目录 /usr/local/nginx/sbin

./nginx 启动 
./nginx -s stop 快速停止 
./nginx -s quit 优雅关闭,在退出前完成已经接受的连接请求 
./nginx -s reload 重新加载配置

由于此时没有设置防火墙,无法在浏览器上访问 

5、防火墙

关闭防火墙

systemctl stop firewalld.service

放行端口,nginx 的端口是80

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

重启防火墙

firewall-cmd --reload

此时启动 nginx,可以用下面的指令查看是否启动

ps -ef | grep nginx

只要有 worker process 

然后在浏览器输入自己的 IP(可以用 ifconfig 查看) ,出现下面的界面

6、安装成系统服务

创建服务脚本

vi /usr/lib/systemd/system/nginx.service

服务脚本内容

[Unit]
Description=nginx - web server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecQuit=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target

重新加载系统服务

systemctl daemon-reload

启动服务

systemctl start nginx.service

7、设置开机启动

systemctl enable nginx.service

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值