Apache 单IP 多域名 多站点 配置

  |   0 评论   |   0 浏览

layout: post
title: Apache 单IP 多域名 多站点 配置
subtitle: 系统环境:centos 7 + apache 2.4.6 + php + mysql
date: 2017-09-04
author: Shuaiqijun
header-img: img/post-bg-hacker.jpg
catalog: true
tags:

  • Apahce
  • Linux技巧

前言

参考链接:How To Set Up Apache Virtual Hosts on CentOS 7

近日因为需要,需要在一个公网IP的服务器上配置多个网站,不同的域名访问不同的网站,用到了Apache的Virtualhost

系统环境:centos 7 + apache 2.4.6  + php  + mysql

正文

# 创建网站目录
mkdir -p /var/www/shuaiqijun.com/public_html    #  帅旗军个人博客 
mkdir -p /var/www/hmgzh.net/public_html         #  黄梅门户网网站



# www目录755权限
chmod -R 755 /var/www



# 创建主页
vi /var/www/shuaiqijun.com/public_html/index.html    #添加任意内容



# 创建Virtual配置目录
mkdir /etc/httpd/sites-available
mkdir /etc/httpd/sites-enabled



# 配置httpd.conf
vi /etc/httpd/conf/httpd.conf
# 添加以下内容
IncludeOptional sites-enabled/*.conf
注释掉# DocumentRoot "/var/www/html"



# 创建网站Virtual配置文件
vi /etc/httpd/sites-available/shuaiqijun.com.conf
# 添加以下内容
<VirtualHost *:80>
    ServerName www.shuaiqijun.com
    ServerAlias shuaiqijun.com
    DocumentRoot /var/www/shuaiqijun.com/public_html
</VirtualHost>
<Directory "/var/www/shuaiqijun.com">  
    Options +Includes -Indexes 
    AllowOverride All
    Require all granted  
</Directory>



#创建链接
ln -s /etc/httpd/sites-available/shuaiqijun.com.conf /etc/httpd/sites-enabled/shuaiqijun.com.conf



#配置HOSTS
vi /etc/hosts
# 更改如下
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
10.100.18.100 shuaiqijun.com
10.100.18.100 hmgzh.net

#重启Apache
systemctl restart httpd

Title:Apache 单IP 多域名 多站点 配置
Link:https://shuaiqijun.com/articles/2021/02/01/1612172313136.html