网站排名套餐,wordpress改目录域名,做网站那个平台好,建设官网公司地址当我们只有一台linux服务器资源但有创建多个网站的需求时#xff0c;我们可以通过安装一个网站服务器Apache进行搭建#xff0c;此次服务器使用Centos 7
下面分别介绍一个域名多个端口和多个域名用Apache来搭建多个网站的操作过程。
一、使用apache 服务器 #xff08;一…当我们只有一台linux服务器资源但有创建多个网站的需求时我们可以通过安装一个网站服务器Apache进行搭建此次服务器使用Centos 7
下面分别介绍一个域名多个端口和多个域名用Apache来搭建多个网站的操作过程。
一、使用apache 服务器 一个域名的多个端口
1. 安装 Apache 服务 sudo yum install httpd 2. 启动 Apache 服务 sudo systemctl start httpd
3. 在 /var/www/ 目录下创建两个网站文件夹假设它们分别为 site1 和 site2 以下是默认创建的两个文件夹 sudo mkdir /var/www/site1 sudo mkdir /var/www/site2 4. 将 site1 和 site2 文件夹的权限分别设置为 Apache 用户 sudo chown -R apache: /var/www/site1 sudo chown -R apache: /var/www/site2
chown 是更改Linux系统上文件和目录的所有权命令。-R 选项表示递归recursive将更改指定目录及其所有子目录和文件的拥有者。apache 表示要更改拥有者为 apache 用户。: 后是要更改的组这里是 apache 组如果该组不存在可以无需在这里指定chown 命令会自动创建。/var/www/site1 是要更改拥有者的目录路径。
5. 创建两个网站的网页文件比如 echo This is site1 | sudo tee /var/www/site1/index.html echo This is site2 | sudo tee /var/www/site2/index.html
命令解释如下
echo 命令表示输出指定的文本。This is site1 是您要输出的文本。您可以将其更改为您自己的HTML代码以自定义您的网站。| 管道符号将上一个命令的输出重定向到下一个命令的输入。sudo tee 命令将标准输入中的内容保存到指定的文件中。使用 sudo 是因为普通用户没有写入 /var/www/site1 的权限。
6. 首先修改 Apache 的主配置文件假设您要使用域名的不同端口来访问这两个网站比如 site1.com:8080 和 site1.com:8081 vim /etc/httpd/conf/httpd.conf 找到以下行 #Listen 12.34.56.78:80 Listen 80
添加监听
Listen 80
Listen 8080
Listen 8081 然后我们再将配置文件 /usr/share/doc/httpd-2.4.6/httpd-vhosts.conf 复制 /etc/httpd/conf.d/
cp /usr/share/doc/httpd-2.4.6/httpd-vhosts.conf /etc/httpd/conf.d/
然后编辑复制过来的文件可以在直接改也可以直接在下面进行添加 virtualhost 47.120.35.180:8080 documentroot /var/www/site1 /virtualhost
virtualhost 47.120.35.180:8081 documentroot /var/www/site2 /virtualhost 7. 现在重新启动 Apache 服务 sudo systemctl restart httpd
或者 sudo systemctl status httpd.service
如果启动失败 需要查看日志信息 cat /var/log/messages
没有启动的原因可能是端口不安全导致
需要添加安全端口
命令行输入
semanage port -a -t http_port_t -p tcp 8080
semanage port -a -t http_port_t -p tcp 8081 现在您可以通过以下 URL 访问这两个网站 - http://site1.com:8080 - http://site1.com:8081
###如果访问网站发现出现apache 测试页需要到/etc/httpd/conf.d/下的 welcome.conf 注销掉重新访问 二、使用apache 服务器 多个域名 1. 安装 Apache 服务 sudo yum install httpd 2. 启动 Apache 服务 sudo systemctl start httpd
3. 在 /var/www/ 目录下创建两个网站文件夹假设它们分别为 site1 和 site2 以下是默认创建的两个文件夹 sudo mkdir /var/www/site1 sudo mkdir /var/www/site2 4. 将 site1 和 site2 文件夹的权限分别设置为 Apache 用户 sudo chown -R apache: /var/www/site1 sudo chown -R apache: /var/www/site2
chown 是更改Linux系统上文件和目录的所有权命令。-R 选项表示递归recursive将更改指定目录及其所有子目录和文件的拥有者。apache 表示要更改拥有者为 apache 用户。: 后是要更改的组这里是 apache 组如果该组不存在可以无需在这里指定chown 命令会自动创建。/var/www/site1 是要更改拥有者的目录路径。
5. 创建两个网站的网页文件比如 echo This is site1 | sudo tee /var/www/site1/index.html echo This is site2 | sudo tee /var/www/site2/index.html
命令解释如下
echo 命令表示输出指定的文本。This is site1 是您要输出的文本。您可以将其更改为您自己的HTML代码以自定义您的网站。| 管道符号将上一个命令的输出重定向到下一个命令的输入。sudo tee 命令将标准输入中的内容保存到指定的文件中。使用 sudo 是因为普通用户没有写入 /var/www/site1 的权限。
6.首先将默认文件拷贝到/etc/httpd/conf.d/下 例如2.4.6版本下的apache /usr/share/doc/httpd-2.4.6/httpd-vhosts.conf 复制 /etc/httpd/conf.d/
命令cp /usr/share/doc/httpd-2.4.6/httpd-vhosts.conf /etc/httpd/conf.d/
然后编辑复制过来的文件可以在直接改也可以直接在下面进行添加
VirtualHost 47.120.35.180:80 # ServerAdmin webmasterdummy-host.example.com DocumentRoot /var/www/site1 ServerName xcx.senmumu.cn # ServerAlias www.dummy-host.example.com # ErrorLog /var/log/httpd/dummy-host.example.com-error_log # CustomLog /var/log/httpd/dummy-host.example.com-access_log common /VirtualHost
VirtualHost 47.120.35.180:80 # ServerAdmin webmasterdummy-host2.example.com DocumentRoot /var/www/site2 ServerName xcx.senmumu.com # ErrorLog /var/log/httpd/dummy-host2.example.com-error_log # CustomLog /var/log/httpd/dummy-host2.example.com-access_log common /VirtualHost 7. 现在重新启动 Apache 服务 sudo systemctl restart httpd
或者 sudo systemctl status httpd.service