Tony's Blog

Bitnami配置虚拟host,配置站点

  • 安装完bitnami lamp环境后(参考文章:Bitnami 一键安装lamp环境),我们需要配置站点,以方便通过域名直接访问,而不是通过站点的路径来访问。

  • 首先我们来看看bitnami lamp环境的配置文件
    所以的配置文件都在安装目录底下,例如apache配置文件存放在/opt/bitnami/apache/conf底下

  • 自定义的站点存放结构
    一般来说,bitnami所有应用应该存放在/opt/bitnami/apps里面,以方便我们管理。
    一个站点完整的组成部分为:

    • 站点目录 /opt/bitnami/apps/{your site folder}
    • 站点配置 /opt/bitnami/apps/{your site folder}/conf
    • 站点代码 /opt/bitnami/apps/{your site folder}/htdocs

    Eg: 新建一个本地站点marketEg: 新建一个本地站点market

    • 站点目录 /opt/bitnami/apps/market
    • 站点配置 /opt/bitnami/apps/market/conf
    • 站点代码 /opt/bitnami/apps/market/htdocs

    Tony's blog image

  • 配置virtual host
    配置站点并绑定域名,分配一个自定义端口。
    首先,我们在配置文件夹创建四个文件htaccess.conf httpd-app.conf httpd-prefix.conf httpd-vhosts.conf
    1.httpd-app.conf是主要的配置文件,通过它可以根据站点来配置不同的内容,为了安全起见,建议不要设置AllowOverride All,bitnami存放配置的文件是installdir/apps/myapp/conf/htaccess.conf

  1. <Directory "installdir/apps/myapp/htdocs">
  2. Options +MultiViews
  3. AllowOverride None
  4. <IfVersion < 2.3 >
  5. Order allow,deny
  6. Allow from all
  7. </IfVersion>
  8. <IfVersion >= 2.3>
  9. Require all granted
  10. </IfVersion>
  11. </Directory>
  12. Include installdir/apps/myapp/conf/htaccess.conf

2.httpd-prefix.conf是在“prefix”模块传递应用的默认配置,例如http://example.com/myapp

  1. Alias /myapp/ "installdir/apps/myapp/htdocs/"
  2. Alias /myapp "installdir/apps/myapp/htdocs"
  3. Include "installdir/apps/myapp/conf/httpd-app.conf"

3.httpd-vhosts.conf包含了虚拟服务器的配置,可以配置不同的端口

  1. <VirtualHost *:8080>
  2. ServerName myapp.example.com
  3. DocumentRoot "installdir/apps/myapp/htdocs"
  4. Include "installdir/apps/myapp/conf/httpd-app.conf"
  5. </VirtualHost>
  6. <VirtualHost *:8444>
  7. ServerName myapp.example.com
  8. DocumentRoot "installdir/apps/myapp/htdocs"
  9. SSLEngine on
  10. SSLCertificateFile "installdir/apps/myapp/conf/certs/server.crt"
  11. SSLCertificateKeyFile "installdir/apps/myapp/conf/certs/server.key"
  12. Include "installdir/apps/myapp/conf/httpd-app.conf"
  13. </VirtualHost>
  • 如果是虚拟hosts,配置完以上的文件,你的站点还不能直接访问,还需要更改一下配置
    • 删除或者注释掉installdir/apache2/conf/bitnami/bitnami-apps-prefix.conf一行代码
      Include "installdir/apps/myapp/conf/httpd-prefix.conf"
    • 添加一行新的配置至installdir/apache2/conf/bitnami/bitnami-apps-vhosts.conf
      Include "installdir/apps/myapp/conf/httpd-vhosts.conf"
    • 重启apache,使配置生效
      sudo /opt/bitnami/ctlscript.sh restart apache
      通过上篇文章,我配置了market站点的端口为8080,httpd-vhosts.conf配置如下
      Tony's blog image

这里要说明的一点是,有时候你开启了某个端口,但是不生效,需要在apache配置文件中添加Listen {your port},然后重启apache才会生效
Tony's blog image