zoukankan      html  css  js  c++  java
  • MAC为Apache2服务器配置多个虚拟主机

    Mac 下自带的 Apache 配置

    参考:

    http://www.cnblogs.com/snandy/archive/2012/11/13/2765381.html

    设置虚拟主机

    1. 在终端运行“sudo vi /etc/apache2/httpd.conf”,打开Apche的配置文件
    2.  
      #LoadModule rewrite_module modules/mod_rewrite.so 
      改为  LoadModule rewrite_module modules/mod_rewrite.so 
      <Directory />
         AllowOverride None   改为  AllowOverride All
         Require all denied
      </Directory>
       
    3. 在httpd.conf中找到“#Include /private/etc/apache2/extra/httpd-vhosts.conf”,去掉前面的“”,保存并退出。
    4. 运行“sudo apachectl restart”,重启Apache后就开启了虚拟主机配置功能。
    5. 运行“sudo vi /etc/apache2/extra/httpd-vhosts.conf”,就打开了配置虚拟主机文件httpd-vhost.conf,配置虚拟主机了。需要注意的是该文件默认开启了两个作为例子的虚拟主机:
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      <VirtualHost *:80>
          ServerAdmin webmaster@dummy-host.example.com
          DocumentRoot "/usr/docs/dummy-host.example.com"
          ServerName dummy-host.example.com
          ErrorLog "/private/var/log/apache2/dummy-host.example.com-error_log"
          CustomLog "/private/var/log/apache2/dummy-host.example.com-access_log" common
      </VirtualHost>
       
      <VirtualHost *:80>
          ServerAdmin webmaster@dummy-host2.example.com
          DocumentRoot "/usr/docs/dummy-host2.example.com"
          ServerName dummy-host2.example.com
          ErrorLog "/private/var/log/apache2/dummy-host2.example.com-error_log"
          CustomLog "/private/var/log/apache2/dummy-host2.example.com-access_log" common
      </VirtualHost>

      而实际上,这两个虚拟主机是不存在的,在没有配置任何其他虚拟主机时,可能会导致访问localhost时出现如下提示:

      1.  
        Forbidden
      2.  
        You don't have permission to access /index.php on this server

      最简单的办法就是在它们每行前面加上#,注释掉就好了,这样既能参考又不导致其他问题。

    6. 增加如下配置
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      <VirtualHost *:80>
          DocumentRoot "/Library/WebServer/Documents"
          ServerName localhost
          ErrorLog "/private/var/log/apache2/localhost-error_log"
          CustomLog "/private/var/log/apache2/localhost-access_log" common
      </VirtualHost>
       
      <VirtualHost *:80>
          DocumentRoot "/Users/snandy/work"
          ServerName mysites
          ErrorLog "/private/var/log/apache2/sites-error_log"
          CustomLog "/private/var/log/apache2/sites-access_log" common
          <Directory />
                      Options Indexes FollowSymLinks MultiViews
                      AllowOverride None
                      Order deny,allow
                      Allow from all
            </Directory>
      </VirtualHost>

      保存退出,并重启Apache。

    7. 运行“sudo vi /etc/hosts”,打开hosts配置文件,加入"127.0.0.1 mysites",这样就可以配置完成sites虚拟主机了,可以访问“http://mysites”了
       apache配置thinkphp5
      <VirtualHost *:80>
        ServerName www.域名.com
        DocumentRoot "/var/www/项目/public"
        <Directory "/var/www/项目/public">
          Options +Indexes +Includes +FollowSymLinks +MultiViews
          AllowOverride All
          Require all granted
        </Directory>
      </VirtualHost>
    httpd.conf最后一行加入
    IncludeOptional conf.d/*.conf,
    重启apache:systemctl restart httpd.service
     
        若安装了 Sublime ,直接在命令行下 open +文件名,会使用 sublime 打开文件。vi 编辑体验不佳
     
     
     
    另有方法、在一个目录下,有index.html 然后在该目录下 用命令行执行 :python -m SimpleHTTPServer  可以开启一个8000端口的web服务,服务器名字:localhost
     
  • 相关阅读:
    使用JDBC连接MySql时出现:The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration
    Mysql Lost connection to MySQL server at ‘reading initial communication packet', system error: 0
    mysql-基本命令
    C# 监听值的变化
    DataGrid样式
    C# 获取当前日期时间
    C# 中生成随机数
    递归和迭代
    PHP 时间转几分几秒
    PHP 根据整数ID,生成唯一字符串
  • 原文地址:https://www.cnblogs.com/nyfz/p/8663533.html
Copyright © 2011-2022 走看看