虚拟网站管理系统,WordPress D8 5.1,seo搜索引擎优化是利用,网站开发补全目录
首先介绍一下Apache和nginx#xff1a;
Nginx和Apache的不同之处#xff1a;
虚拟主机
准备工作
Apache实现#xff1a;
方法1#xff1a;使用不同的ip来实现
方法2#xff1a;使用相同的ip#xff0c;不同的端口来实现
方法3#xff1a;使用相同的ip…目录
首先介绍一下Apache和nginx
Nginx和Apache的不同之处
虚拟主机
准备工作
Apache实现
方法1使用不同的ip来实现
方法2使用相同的ip不同的端口来实现
方法3使用相同的ip相同的端口不同的主机名域名
Nginx实现
方法1使用不同的ip来实现
方法2使用相同的ip不同的端口来实现
方法3使用相同的ip相同的端口不同的主机名域名 首先介绍一下Apache和nginx
ApacheApache HTTP Server是一个模型化的服务器可以运行在几乎所有的服务器上。其属于应用服务器
特点支持模块多、性能稳定、Apache本身是静态解析适合静态HTML、图片但是可以通过扩展脚本、模块等支持动态页面等
Nginx是俄罗斯人编写的十分轻量级的HTTP服务器是一个高性能的HTTP和反向代理服务器同时也是一个IMAP/POP3/SMTP代理服务器
特点占有内存少并发能力强、抑郁开发、部署方便。Niginx支持多语言通用服务器
Nginx和Apache的不同之处
Nginx配置简介Apache较为复杂Nginx静态处理性能比Apache高很多Apache是同步多进程模型一个连接诶对应一个进程Nginx是异步的多个连接可以对一个进程Nginx处理静态文件好耗费内存少动态请求Apache比较擅长Nginx更适合去做静态和反向Nginx适合做前端服务器负载性能很好Nginx本身就是一个反向代理服务器且支持负载均衡
虚拟主机
解决的问题解决一台web服务器运行多个web应用
准备工作
首先本次测试环境运行在虚拟机中使用center os 7
然后进入配置文件中
vim /etc/httpd/conf/httpd.conf 找到上图的位置
1.将ServerName前的注释删除即开启了www.example.com这个域名的访问
2.将Require all denied修改为 granted 即允许所有的请求 3.找到这里增加一条作用是配置php的配置环境让php可以正常使用 4.找到这里在后面增加一个 index.php即增加了一个php页面
配置完成后重启http服务
systemctl start httpd配置LNMP环境
安装所有需要的软件包
yum install epel-release.noarch
yum install nginx mariadb-server.x86_64 mariadb php php-fpm.x86_64 php-mysql -y
关闭selinux
setenforce 0
启动
systemctl start nginx
systemctl start php-fpm.service Apache实现
方法1使用不同的ip来实现
1首先创建一个目录 mkdir /www/ 2创建日志存放的目录 mkdir /www/logs
3为两个目录下的index.html写入内容
echo Hello Apache /www/index.html
4为网卡ens160增加一个ip地址
nmcli connection modify ens33 ipv4.addresses 192.168.159.250/24 ipv4.method manual
5激活该地址
nmcli con up ens33
6安装离线帮助包
dnf install -y httpd-manual
7重启httpd服务
systemctl restart httpd
8在浏览器中打开帮助手册192.168.159.200/mantal Apache HTTP Server Version 2.4 Documentation - Apache HTTP Server Version 2.4
9进入配置路径
cd /etc/httpd/conf.d/
10 vim VirtualHost.conf 将以下内容写入
Directory /www/Options Indexes FollowSymLinksAllowOverride None Require all granted
/Directory
VirtualHost 192.168.159.200:80 DocumentRoot /www ServerName www1.example.com ErrorLog /www/logs/error_logCustomLog /www/logs/access_log combined
/VirtualHost
VirtualHost 192.168.159.250:80 DocumentRoot /www ServerName www2.example.com ErrorLog /www/logs/error_log CustomLog /www/logs/access_log combined
/VirtualHost
11检查一下是否有语法错误
httpd -t 12重启httpd
systemctl restart httpd
注如果这里不成功很有可能和selinux有关
关闭selinux
setenforce 0
13使用浏览器测试 可以看到我们成功的实现了不同的ip地址访问同一个资源
方法2使用相同的ip不同的端口来实现
1首先将上面添加的ip删除
nmcli connection modify ens33 -ipv4.addresses 192.168.159.250/24 ipv4.method manual
nmcli con up ens33
3vim /etc/http/conf.d/VirtualHost写入以下内容
Listen 81
Listen 82
Directory /www/
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
/Directory
VirtualHost 192.168.159.200:81DocumentRoot /www ServerName www1.example.comErrorLog /www/logs/error_logCustomLog /www/logs/access_log combined
/VirtualHost
VirtualHost 192.168.159.200:82 DocumentRoot /www ServerName www2.example.com ErrorLog /www/logs/error_logCustomLog /www/logs/access_log combined
/VirtualHost
4重启httpd
systemctl restart httpd
5防火墙放行81和82端口 firewall-cmd --permanent --add-port81-82/tcpsuccess
firewall-cmd --reload 让防火墙立即生效success
6使用浏览器进行测试 方法3使用相同的ip相同的端口不同的主机名域名
1将配置文件修改为
Directory /www/
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
/Directory
VirtualHost 192.168.159.200:80DocumentRoot /wwwServerName www1.example.comErrorLog /www/logs/error_logCustomLog /www/logs/access_log combined
/VirtualHost
VirtualHost 192.168.159.200:80DocumentRoot /www ServerName www2.example.com ErrorLog /www/logs/error_logCustomLog /www/logs/access_log combined
/VirtualHost2重启 systemctl restart httpd
3在windowC:\Windows\System32\drivers\etc的路径中的hosts中添加对应关系
192.168.159.200 www1.example.com www2.example.com测试 Nginx实现
方法1使用不同的ip来实现
为当前网卡增加一个ip
nmcli con modify ens33 ipv4.addresses 192.168.159.222/24
nmcli con up ens33 注这里将ip地址修改为自己主机一个网段的ip地址
创建文件夹
mkdir /www/
为主页面中写入内容vim index.html
hello 我的路径是www/index.html
为这个页面创建日志文件后面配置虚拟主机会用到
mkdir /www/logs
然后修改配置文件
vim /etc/nginx/conf.d/test.conf
将以下内容写入
server {listen 80;server_name 192.168.159.200;charset utf-8;index index.html;root /www/;
}
server {listen 80;server_name 192.168.159.201;charset utf-8;index index.html;root /www/;}
测试 根据结果我们可以看到使用不容的ip地址访都问到了我们写的主页面
方法2使用相同的ip不同的端口来实现
这里首先将之前新增加的ip删除掉
nmcli con modify ens33 -ipv4.addresses 192.168.159.201
nmcli con up ens33
修改虚拟主机为
server {listen 81;server_name 192.168.159.200;charset utf-8;index index.html;root /www/web1;
}
server {listen 82;server_name 192.168.159.200;charset utf-8;index index.html;root /www/web2;}
防火墙放行tcp81/82端口或者关闭防火墙
上面的Apache实现时使用了方形端口那我这里直接关闭防火墙
systemctl stop firewall.service
重启nginx服务
systemctl restart nginx.service
测试 方法3使用相同的ip相同的端口不同的主机名域名
修改配置文件为
server {listen 80;server_name www1.example.com;charset utf-8;index index.html;root /www/web1;
}
server {listen 80;server_name www2.example.com;charset utf-8;index index.html;root /www/web2;}
在window主机中的host中增加对应关系
192.168.159.200 www1.example.com
192.168.159.200 www2.example.com
测试 到这里Nginx和Apache三种虚拟主机的配置就已经全部完成了