Nginx 是一个高性能的HTTP和反向代理web服务器
创建 Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
# time: 2022/11/24
Vagrant.configure("2") do |config|
# https://docs.vagrantup.com.
# boxes at https://vagrantcloud.com/search.
config.vm.box = "centos7"
config.vm.define "web_vagrant",primary: true do |mastera|
mastera.vm.hostname = "web"
mastera.vm.network "private_network",ip:"192.168.56.23"
mastera.vm.provider "virtualbox" do |vb|
vb.name = "web_vagrant"
#vb.gui = "true"
vb.memory = 512
vb.cpus = 1
end
end
config.vm.provision "shell", path: "web.sh"
# config.vm.box_check_update = false
# config.vm.network "forwarded_port", guest: 80, host: 8080
# config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
# config.vm.network "private_network", ip: "192.168.33.10"
# config.vm.network "public_network"
# config.vm.synced_folder "../data", "/vagrant_data"
end
在 Vagrantfile 文件同目录下创建 web.sh 脚本文件
# vagrant + nginx
# 20221127
# Install web Server
echo "获取root权限"
sudo -i
echo "关闭Selinux"
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
echo "开放80端口"
firewalld-cmd --query-port=80/tcp
firewalld-cmd --add-port=80/tcp --permanent
firewalld-cmd --reload
echo "安装所需软件包"
yum clean all
yum makecache fast
yum -y update
yum -y install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel wget
echo "编译nginx"
cd /usr/local
wget https://nginx.org/download/nginx-1.22.0.tar.gz
tar -zxvf nginx-1.22.0.tar.gz
rm -rf nginx-1.22.0.tar.gz
cd nginx-1.22.0
./configure && make && make install
echo "配置nginx开机启动"
cat > /lib/systemd/system/nginx.service <<EOF
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart= /usr/local/nginx/sbin/nginx
ExecReload= /usr/local/nginx/sbin/nginx reload
ExecStop= /usr/local/nginx/sbin/nginx quit
PrivateTmp= true
[Install]
WantedBy=multi-user.target
EOF
echo "设置开机启动"
systemctl enable nginx.service
echo "启动nginx"
systemctl start nginx.service