2015-07-04 23:28:40 11572次浏览 3条回答 3 悬赏 10 金钱

操作系统 centos6.6
web服务器 nginx1.6.2
数据库为 mysql
开发语言 php5.6.3
yii框架版本:2.0

问题:nginx+mysql+php已安装成功,http://127.0.0.1 显示php版本信息成功,yii2安装的为高级版本 安装路径为/var/www/yii-test,对应的./init也成功了。问题来了,如何进行配置、配置那些内容才能让 http://127.0.0.1/frontend/web/index.phphttp://127.0.0.1/backend/web/index.php好用?求大侠、高手指点指点。

最佳答案

  • chocoboxxf 发布于 2015-07-05 09:49 举报

    backend和frontend分开配置,可以配置不同端口,比如一个用listen 8000,一个listen 8080,也可以配置不同域名,比如一个server_name www.backend.com,一个server_name www.frontend.com,生产环境中如果需要用到不同子域名,只需要配置不同的server_name,可以都使用80端口。具体例子如下(使用php-fpm):

    #backend配置
    server {
        charset utf-8;
        client_max_body_size 128M;
    
        listen 8000; ## listen for ipv4
        #listen [::]:80 default_server ipv6only=on; ## listen for ipv6
    
        server_name www.backend.com;
        root        /var/www/yii-test/backend/web;
        index       index.php;
    
    
        access_log  /var/www/yii-test/access.backend.log main;
        error_log   /var/www/yii-test/error.backend.log;
    
        location / {
            # Redirect everything that isn't a real file to index.php
            try_files $uri $uri/ /index.php?$args;
        }        
    
        location ~ \.php$ {
            include fastcgi.conf;
            fastcgi_pass   127.0.0.1:9000;
            #fastcgi_pass unix:/var/run/php5-fpm.sock;
            try_files $uri =404;
        }
        
        error_page 404 /404.html;
    
        location ~ /\.(ht|svn|git) {
            deny all;
        }
    }
    
    #frontend配置
    server {
        charset utf-8;
        client_max_body_size 128M;
    
        listen 8080; ## listen for ipv4
        #listen [::]:80 default_server ipv6only=on; ## listen for ipv6
    
        server_name www.frontend.com;
        root        /var/www/yii-test/backend/web;
        index       index.php;
    
    
        access_log  /var/www/yii-test/access.frontend.log main;
        error_log   /var/www/yii-test/error.frontend.log;
    
        location / {
            # Redirect everything that isn't a real file to index.php
            try_files $uri $uri/ /index.php?$args;
        }        
    
        location ~ \.php$ {
            include fastcgi.conf;
            fastcgi_pass   127.0.0.1:9000;
            #fastcgi_pass unix:/var/run/php5-fpm.sock;
            try_files $uri =404;
        }
        
        error_page 404 /404.html;
    
        location ~ /\.(ht|svn|git) {
            deny all;
        }
    }
    
    觉得很赞
您需要登录后才可以回答。登录 | 立即注册
llg8844
职场新人

llg8844

注册时间:2015-06-04
最后登录:2015-09-12
在线时长:7小时10分
  • 粉丝2
  • 金钱0
  • 威望0
  • 积分70

热门问题