yii 后台配置独立子域名方法

我这里安装的是宝塔面板集成的环境WNMP,官网上虽然也有,但是写的并不明确,对我这种用YII的新手来说也很头疼,折腾了半天终于弄好,记录一下。

首先解析一个子域名:back.domain.com;

用宝塔面板创建了一个网站,domain.com;

找到Nginx的配置文件夹  conf/vhost,此文夹中已然存在了一个domain.com.conf 文件,复制一份,重命名为back.domain.com.conf;

domain.com.conf 代码:

#START-SITE
server {
    listen 80;
    server_name  yii.com;
    access_log  logs/yii.com.access.log;
    root   D:/wwwroot/yii;
    index  index.php default.php index.html index.htm default.html default.htm;
    
    include rewrite/yii.com.conf;
        
    location ~ \.php$ {
        root   D:/wwwroot/yii;
        fastcgi_pass   127.0.0.1:4570;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

}
#END-SITE

参照YII官网上的介绍https://github.com/yiisoft/yii2-app-advanced/blob/master/docs/guide-zh-CN/start-installation.md,简单的修改一下,修改后的 back.domain.com.conf 文件代码

#START-SITE
server {
    charset utf-8;
    client_max_body_size 128M;

    listen 80; ## listen for ipv4
    #listen [::]:80 default_server ipv6only=on; ## listen for ipv6

    server_name back.yii.com;                     ##前台域名
    root        D:/wwwroot/yii/backend/web;   ##这是前台index地址
    index       index.php;


    #access_log   D:/wwwroot/yii/access.backend.log main;
    #error_log    D:/wwwroot/yii//error.backend.log;

    location / {
        # Redirect everything that isn't a real file to index.php
        try_files $uri $uri/ /index.php?$args;
    }        

    location ~ \.php$ {
        root   D:/wwwroot/yii/backend/web;
        fastcgi_pass   127.0.0.1:4570;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
    #error_page 404 /404.html;

    location ~ /\.(ht|svn|git) {
        deny all;
    }
}
#END-SITE

猜你喜欢

转载自www.cnblogs.com/intinity/p/9263608.html
yii