• [记录] Ubuntu 配置Apache虚拟站点


    版本 Ubuntu 16.04

    1 . 首先找到Apapche配置文件夹  /etc/apache2/ 

    apache2.conf conf-enabled magic mods-enabled sites-available
    conf-available envvars mods-available ports.conf sites-enabled

    该文件夹下有以上配置文件

    apache2.conf : apache配置主文件  配置站点根目录 全局配置等

    sites-available :配置虚拟主机

    sites-enabled : 持有/etc/apache2/sites-available目录下文件的链接,当Apache重启后,该目录中包含的站点将会被激活。如果apache上配置了多个虚拟机,每个虚拟机的配置文件都放在sites-available下,那么对于虚拟主机的停用,启动就是非常方便了,操作某个虚拟主机就不用动配置文件了

    2. 在sites-available下创建虚拟站点 (eko.conf)

    root@ubuntu:/etc/apache2/sites-available# ls
    000-default.conf  default-ssl.conf  eko.conf

    配置文件项

    <VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
    ServerName eko.xiao.com ServerAdmin webmaster@localhost DocumentRoot
    /var/www/html/eko/public <Directory /var/www/html/eko/public> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, # error, crit, alert, emerg. # It is also possible to configure the loglevel for particular # modules, e.g. #LogLevel info ssl:warn ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined # For most configuration files from conf-available/, which are # enabled or disabled at a global level, it is possible to # include a line for only one particular virtual host. For example the # following line enables the CGI configuration for this host only # after it has been globally disabled with "a2disconf". #Include conf-available/serve-cgi-bin.conf </VirtualHost>

    3 . 创建软链接

    sudo ln -s /etc/apache2/sites-available/example.conf  /etc/apache2/sites-enabled/example.conf 

    在Ubuntu缺省安装的目录有与其他相比有一点不同。在ubuntu中module和 virtual host的配置都有两个目录,一个是available,一个是enabled,available目录是存放有效的内容,但不起作用,只有用ln 连到enabled过去才可以起作用。这样子对于开发以及调试都很方便

    4 . 修改/etc /hosts 文件,加入当前主机的IP地址和需要设置的虚拟主机名

    127.0.0.1   localhost
    127.0.1.1   ubuntu
    192.168.1.121 eko.test.com
    # The following lines are desirable for IPv6 capable hosts
    ::1     ip6-localhost ip6-loopback
    fe00::0 ip6-localnet
    ff00::0 ip6-mcastprefix
    ff02::1 ip6-allnodes
    ff02::2 ip6-allrouters

    5.  重启apache

     /etc/init.d/apache2 restart
    

    6 .  配置完成后将项目根目录 runtime 目录 public目录 权限设置为777

    chmod -R 777 runtime 
    chmod -R 777 public/upload
    

      

  • 相关阅读:
    搭建LNAMP环境(四)- 源码安装PHP7
    搭建LNAMP环境(三)- 源码安装Apache2.4
    搭建LNAMP环境(二)- 源码安装Nginx1.10
    搭建LNAMP环境(一)- 源码安装MySQL5.6
    Yii2框架RESTful API教程(二)
    Yii2框架RESTful API教程(一)
    PHP实现RESTful风格的API实例(三)
    centos7部署elk集群(filebeat+kafka+logstash+elasticsearch+kibana)
    centos7部署kafka+zookeeper集群
    ElasticSearch7.5.2通过模板管理索引副本数、分片
  • 原文地址:https://www.cnblogs.com/xiaoliwang/p/9216148.html
Copyright © 2020-2023  润新知