垡头街道网站建设,plc编程培训机构,网站上门备案,长沙哪里学网站建设文章和代码已经归档至【Github仓库#xff1a;https://github.com/timerring/front-end-tutorial 】或者公众号【AIShareLab】回复 nginx 也可获取。 文章目录 虚拟机安装CentOS7.4Linux配置配置上网配置静态ip Nginx的安装版本区别备份克隆 安装编译安装报错解决 启动Nginx防… 文章和代码已经归档至【Github仓库https://github.com/timerring/front-end-tutorial 】或者公众号【AIShareLab】回复 nginx 也可获取。 文章目录 虚拟机安装CentOS7.4Linux配置配置上网配置静态ip Nginx的安装版本区别备份克隆 安装编译安装报错解决 启动Nginx防火墙 安装成系统服务 虚拟机VMware workstation 16 操作系统CentOS 7.4 下载地址https://vault.centos.org/centos/7.4.1708/isos/x86_64/CentOS-7-x86_64-Minimal-1708.iso
建议电脑配置
内存建议8G以上磁盘建议使用SSDCPU4核以上主流即可
虚拟机安装CentOS7.4
1 新建虚拟机
2 典型安装
3 选择CentOS镜像
4 存储位置
5 虚拟机磁盘配置 注意这里只是分配最大磁盘大小实际不会在一开始占用那么多是一个动态的区域在实际实用中逐渐分配。
6 自定义其他配置默认即可。
7 安装系统
默认即可在分区选择时记得点进去确认一下。 接下来继续安装安装过程中可以设置root密码。安装后重启即可。
Linux配置
配置上网
修改配置网卡配置文件Linux中所有设置都是通过修改配置文件实现的
vi /etc/sysconfig/network-scripts/ifcfg-ens33把 ONBOOT 修改为yes即可即重启操作系统时就会重启该网卡。 然后重启网络服务
systemctl restart network重新测试ping可发现网络正常。
可以用 ip addr 测试当前ip地址。
通常为了便于连接服务器以及复制粘贴等功能一般采用XShell作为终端。下载地址https://www.xshell.com/zh/free-for-home-school/
配置静态ip
之前的网络配置是使用dhcp方式分配ip地址这种方式会在系统每次联网的时候分配一个ip给我们用系统下次启动的时候ip会变不方便管理。
配置静态ip首先需要打开网卡配置文件
vi /etc/sysconfig/network-scripts/ifcfg-ens33修改启动协议 BOOTPROTOstatic
手动配置ip地址
IPADDR192.168.44.101
NETMASK255.255.255.0
GATEWAY192.168.44.1
DNS18.8.8.8一些常见的公网DNS服务器 阿里 223.5.5.5
223.6.6.6腾讯 119.29.29.29
182.254.118.118百度 180.76.76.76114DNS 114.114.114.114
114.114.115.115谷歌 8.8.8.8
8.8.4.4注意这里是严格区分大小写的。 样例 TYPEEthernet
PROXY_METHODnone
BROWSER_ONLYno
BOOTPROTOstatic
DEFROUTEyes
IPV4_FAILURE_FATALno
IPV6INITyes
IPV6_AUTOCONFyes
IPV6_DEFROUTEyes
IPV6_FAILURE_FATALno
IPV6_ADDR_GEN_MODEstable-privacy
NAMEens33
UUID10ac735e-0b8f-4b19-9747-ff28b58a1547
DEVICEens33
ONBOOTyes
IPADDR192.168.44.101
NETMASK255.255.255.0
GATEWAY192.168.44.1
DNS18.8.8.8然后重启网络服务即可。
systemctl restart network这里第一次配置时网络仍然无法连接这里我修改了网关与虚拟机的网关保持一致。 虚拟机网关查看方法 编辑--- 虚拟网络编辑器---选择VMnet8---NAT设置---网关IP然后把上述GATEWAY修改为你的网关IP即可。然后就可以ping通了仅供参考。 Nginx的安装
版本区别
常用版本分为四大阵营
Nginx开源版非常纯粹的反向代理负载均衡。 http://nginx.org/
Nginx plus 商业版 https://www.nginx.com
openresty以Lua脚本扩展的nginx http://openresty.org/cn/
Tengine以C语言扩展的nginx http://tengine.taobao.org/
备份克隆
在安装前最好先克隆备份以防安装错误后难以恢复。
首先可以通过 init 0 关闭虚拟机。
然后右键虚拟机选择 管理—克隆选择创建连接克隆这种克隆方法可以比较出两者之间的差异。
安装
编译安装
首先传输nginx安装包然后 tar zxvf nginx-1.21.6.tar.gz 进入解压后的文件夹执行 ./configure 安装由于缺少相关的依赖因此会报错。只需要根据对应的报错安装即可。
./configure --prefix/usr/local/nginx #设置前缀安装到指定的目录下
make
make install报错解决
提示
checking for OSLinux 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提示
./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-pcrepath option.安装perl库
yum install -y pcre pcre-devel提示
./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-zlibpath option.安装zlib库
yum install -y zlib zlib-devel启动Nginx
手动启动的方式进入安装好的目录/usr/local/nginx/sbin 。
./nginx 启动
./nginx -s stop 快速停止
./nginx -s quit 在退出前完成已经接受的连接请求
./nginx -s reload 重新加载配置防火墙
关闭防火墙
systemctl stop firewalld.service禁止防火墙开机启动
systemctl disable firewalld.service放行端口
firewall-cmd --zonepublic --add-port80/tcp --permanent重启防火墙
firewall-cmd --reload关闭防火墙后启动服务可以通过浏览器访问ip验证服务是否启动。若成功则如下所示 安装成系统服务
每次手动启动服务过于复杂可以考虑安装成系统级的服务。
创建服务脚本
vi /usr/lib/systemd/system/nginx.service服务脚本内容
[Unit]
Descriptionnginx - web server
Afternetwork.target remote-fs.target nss-lookup.target
[Service]
Typeforking
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
PrivateTmptrue
[Install]
WantedBymulti-user.target重新加载系统服务
systemctl daemon-reload启动服务
systemctl start nginx.service查看服务状态是否启动
systemctl status nginx.service可以看到服务是已经active的。
开机启动
systemctl enable nginx.service