yii学习历程2-yii相关配置

将basic/web目录从url中去除:

1.Apache服务器配置

推荐使用的 Apache 配置

在 Apache 的 httpd.conf 文件或在一个虚拟主机配置文件中使用如下配置。注意,你应该将 path/to/basic/web 替换为实际的basic/web 目录。

# 设置文档根目录为 “basic/web”
DocumentRoot "path/to/basic/web"

<Directory "path/to/basic/web">
    # 开启 mod_rewrite 用于美化 URL 功能的支持(译注:对应 pretty URL 选项)
    RewriteEngine on
    # 如果请求的是真实存在的文件或目录,直接访问
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    # 如果请求的不是真实文件或目录,分发请求至 index.php
    RewriteRule . index.php

    # ...其它设置...
</Directory>

2.Nginx服务器配置

推荐使用的 Nginx 配置

为了使用 Nginx,你应该已经将 PHP 安装为 FPM SAPI 了。使用如下 Nginx 配置,将 path/to/basic/web 替换为实际的 basic/web 目录,mysite.local 替换为实际的主机名以提供服务。

server {
    charset utf-8;
    client_max_body_size 128M;

    listen 80; ## 监听 ipv4 上的 80 端口
    #listen [::]:80 default_server ipv6only=on; ## 监听 ipv6 上的 80 端口

    server_name mysite.local;
    root        /path/to/basic/web;
    index       index.php;

    access_log  /path/to/basic/log/access.log main;
    error_log   /path/to/basic/log/error.log;

    location / {
        # 如果找不到真实存在的文件,把请求分发至 index.php
        try_files $uri $uri/ /index.php?$args;
    }

    # 若取消下面这段的注释,可避免 Yii 接管不存在文件的处理过程(404)
    #location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
    #    try_files $uri =404;
    #}
    #error_page 404 /404.html;

    location ~ \.php$ {
        include fastcgi.conf;
        fastcgi_pass   127.0.0.1:9000;
        #fastcgi_pass unix:/var/run/php5-fpm.sock;
        try_files $uri =404;
    }

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

使用该配置时,你还应该在 php.ini 文件中设置 cgi.fix_pathinfo=0 ,能避免掉很多不必要的 stat() 系统调用。

还要注意当运行一个 HTTPS 服务器时,需要添加 fastcgi_param HTTPS on; 一行,这样 Yii 才能正确地判断连接是否安全。

(以上摘自http://www.yiichina.com/doc/guide/2.0/start-installation)

(未完待续)


猜你喜欢

转载自blog.csdn.net/jasonsama/article/details/50742380
yii
今日推荐