论坛 新手教程 如何在虚拟主机配置使用魔众系统

如何在虚拟主机配置使用魔众系统

476080112 发表于 阅读:786 回复:0

一定先看

在阅读本文档安装系统时,请确保您已经 熟练掌握 如何使用 apache 或 nginx 的进行网站系统的配置方法。

如果您 不是很了解 或 了解甚少,请直接购买我们的 付费安装服务,同时把服务器信息、需要安装的系统源码提供给我们,我们会帮您配置并安装系统。

非常重要

使用虚拟主机安装需要您对技术有足够的自信,因为很有可能不能自动化完成安装的,需要技术不断的采坑并解决。

我的虚拟主机能不能装?

请自行下载一个环境检测程序来进行虚拟主机环境的检测;

http://www.tecmz.com/env_check.php.zip

使用说明

当使用的是虚拟主机时,通常网站的根目录不能绑定到 <网站目录>/public 目录,因此需要进行特殊的配置。

安装步骤

  1. 配置 apache/nginx 服务器,请将网站的根目录配置到 <网站目录>;

  2. 访问 http://www.example.com/install;

  3. 使用安装引导向导进行安装;

Nginx参考配置

server {    listen       80;    server_name  www.example.com;    charset utf-8;    index index.php index.html;    root /var/www/html/www.example.com;    autoindex off;    location ^~ /.git {        deny all;    }    location ^~ /.env {        deny all;    }    location ^~ /storage/ {        deny all;    }    location / {        try_files /public$uri /public$uri/ /public/index.php?$query_string;    }    location ~ \.php$ {        fastcgi_pass   127.0.0.1:9000;        fastcgi_index  index.php;        fastcgi_param  PHP_VALUE  "open_basedir=/var/www/html/www.example.com/:/tmp/:/var/tmp/";        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;        include fastcgi_params;    }}

Apache参考配置

httpd配置

<VirtualHost *:80>      ServerName www.example.com      DocumentRoot d:/wwwroot/example.com</VirtualHost>

在网站系统根目录增加 .htaccess 文件

<IfModule mod_rewrite.c>    RewriteEngine on    RewriteCond %{REQUEST_URI} !^public    RewriteRule ^(.*)$ public/$1 [L]</IfModule>

IIS参考配置

web.config

<?xml version="1.0" encoding="UTF-8"?><configuration>  <system.webServer>    <directoryBrowse enabled="false" />    <rewrite>      <rules>        <rule name="Imported Rule 3" stopProcessing="true">          <match url="^(.*)$" ignoreCase="false" />          <conditions>            <add input="{APPL_PHYSICAL_PATH}public/{R:1}" matchType="IsFile" ignoreCase="false" negate="true" />          </conditions>          <action type="Rewrite" url="/public/index.php" />        </rule>        <rule name="Imported Rule 1" stopProcessing="true">          <match url="^(.*)$" ignoreCase="false" />          <action type="Rewrite" url="/public/{R:1}" />        </rule>      </rules>    </rewrite>  </system.webServer></configuration>

特殊环境配置说明

阿里云虚拟主机

  1. 需要开启PHP5.5版本;

  2. 由于阿里云禁用了putenv函数,这个函数尤为重要,所以需要打一个函数补丁,在程序最开始(public/index.php)的位置嵌入PHP代码;

putenv函数被禁用补丁代码

<?phpfunction env($key, $defaultValue = null){    static $envFileConfig = null;    if (null === $envFileConfig) {        $envFileConfig = [];        $envFile = file_get_contents(__DIR__ . '/.env');        foreach (explode("\n", $envFile) as $line) {            $line = trim($line);            if (empty($line) || strpos($line, '#') === 0) {                continue;            }            list($k, $v) = explode('=', $line);            $envFileConfig[trim($key)] = trim($value);        }    }    if (array_key_exists($key, $envFileConfig)) {        return $envFileConfig[$key];    }    return $defaultValue;}

郑重说明

在虚拟主机配置环境下,由于网站的所有数据都被暴露在浏览器访问路径下,因此要控制系统的系统文件不被访问到,当您配置好之后,至少要测试一下路径不能直接被用户下载,否则系统将会受到严重威胁。

  • http://www.example.com/.env

  • http://www.example.com/storage/install.lock

我来评论