zoukankan      html  css  js  c++  java
  • yii2 URL重写 nginx的配置

    Url的重写

    nginx的配置文件

    [plain] view plain copy
     
     print?
    1. [root@localhost protected]# vim /etc/nginx/conf.d/default.conf  
    2.   
    3. server {  
    4.     listen       80;  
    5.     server_name  localhost;  
    6.   
    7.     #charset koi8-r;  
    8.     #access_log  /var/log/nginx/log/host.access.log  main;  
    9.   
    10.     location = /favicon.ico {  
    11.         log_not_found off;  
    12.         access_log off;  
    13.     }  
    14.     location = /robots.txt {  
    15.         allow all;  
    16.         log_not_found off;  
    17.         access_log off;  
    18.     }  
    19.   
    20.   
    21.     location / {  
    22.         try_files $uri $uri/ /index.php?$args;      
    23.        if (!-e $request_filename){
    24.              rewrite ^/(.*)$ /index.php?r=$1 last;
    25.         }
    26.         root   /usr/share/nginx/html;  
    27.         index  index.php  index.html  index.htm;  
    28.     }  
    29.   
    30.     location ~ /(protected|framework|nbproject|themes/w+/views|index-test.php) {  
    31.         deny all;  
    32.         # for production  
    33.         internal;  
    34.         log_not_found off;  
    35.         access_log off;  
    36.     }  
    37.   
    38.   
    39.     #error_page  404              /404.html;  
    40.   
    41.     # redirect server error pages to the static page /50x.html  
    42.     #  
    43.     error_page   500 502 503 504  /50x.html;  
    44.     location = /50x.html {  
    45.         root   /usr/share/nginx/html;  
    46.     }  
    47.   
    48.     # proxy the PHP scripts to Apache listening on 127.0.0.1:80  
    49.     #  
    50.     #location ~ .php$ {  
    51.     #    proxy_pass   http://127.0.0.1;  
    52.     #}  
    53.   
    54.     # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000  
    55.     #  
    56.     location ~ .php$ {  
    57.         root           /usr/share/nginx/html;  
    58.         include  fastcgi_params;  
    59.         fastcgi_pass   127.0.0.1:9000;  
    60.         fastcgi_index  index.php;  
    61.         fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script_name;  
    62.        # include        fastcgi_params;  
    63.     }  
    64.   
    65.     # deny access to .htaccess files, if Apache's document root  
    66.     # concurs with nginx's one  
    67.     #  
    68.     #location ~ /.ht {  
    69.     #    deny  all;  
    70.     #}  
    71.   
    72.     # deny access to .htaccess files, if Apache's document root  
    73.     # concurs with nginx's one  
    74.     #  
    75.     location ~ /(.svn|.git|.ht|.DS) {  
    76.         deny all;  
    77.         internal;  
    78.     }  
    79. }  

    yii的配置文件

    [plain] view plain copy
     
     print?
    1. /project/protected/config/main.php  
    2.   
    3. <?php  
    4.   
    5. // uncomment the following to define a path alias  
    6. // Yii::setPathOfAlias('local','path/to/local-folder');  
    7.   
    8. // This is the main Web application configuration. Any writable  
    9. // CWebApplication properties can be configured here.  
    10. return array(  
    11.     'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',  
    12.     'name'=>'My Web Application',  
    13.   
    14.     // preloading 'log' component  
    15.     'preload'=>array('log'),  
    16.   
    17.     // autoloading model and component classes  
    18.     'import'=>array(  
    19.         'application.models.*',  
    20.         'application.components.*',  
    21.     ),  
    22.   
    23.     'modules'=>array(  
    24.         // uncomment the following to enable the Gii tool  
    25.         /*  
    26.         'gii'=>array(  
    27.             'class'=>'system.gii.GiiModule',  
    28.             'password'=>'Enter Your Password Here',  
    29.             // If removed, Gii defaults to localhost only. Edit carefully to taste.  
    30.             'ipFilters'=>array('127.0.0.1','::1'),  
    31.         ),  
    32.         */  
    33.     ),  
    34.   
    35.     // application components  
    36.     'components'=>array(  
    37.   
    38.         'user'=>array(  
    39.             // enable cookie-based authentication  
    40.             'allowAutoLogin'=>true,  
    41.         ),  
    42.   
    43.         // uncomment the following to enable URLs in path-format  
    44.           
    45.         'urlManager'=>array(  
    46.             'urlFormat'=>'path',  
    47.                         'showScriptName' => false,  
    48.                         'urlSuffix' => '.html',  
    49.             'rules'=>array(  
    50.                 '<controller:w+>/<id:d+>'=>'<controller>/view',  
    51.                 '<controller:w+>/<action:w+>/<id:d+>'=>'<controller>/<action>',  
    52.                 '<controller:w+>/<action:w+>'=>'<controller>/<action>',  
    53.             ),  
    54.         ),  
    55.           
    56.   
    57.         // database settings are configured in database.php  
    58.         'db'=>require(dirname(__FILE__).'/database.php'),  
    59.   
    60.         'errorHandler'=>array(  
    61.             // use 'site/error' action to display errors  
    62.             'errorAction'=>'site/error',  
    63.         ),  
    64.   
    65.         'log'=>array(  
    66.             'class'=>'CLogRouter',  
    67.             'routes'=>array(  
    68.                 array(  
    69.                     'class'=>'CFileLogRoute',  
    70.                     'levels'=>'error, warning',  
    71.                 ),  
    72.                 // uncomment the following to show log messages on web pages  
    73.                 /*  
    74.                 array(  
    75.                     'class'=>'CWebLogRoute',  
    76.                 ),  
    77.                 */  
    78.             ),  
    79.         ),  
    80.   
    81.     ),  
    82.   
    83.     // application-level parameters that can be accessed  
    84.     // using Yii::app()->params['paramName']  
    85.     'params'=>array(  
    86.         // this is used in contact page  
    87.         'adminEmail'=>'webmaster@example.com',  
    88.     ),  
    89. );  

    重启nginx

    [plain] view plain copy
     
     print?
      1. [root@localhost protected]# service nginx restart  
      2. 停止 nginx:                                               [确定]  
      3. 正在启动 nginx:                                           [确定]  
  • 相关阅读:
    微软企业库4.1学习笔记(十一)企业库的核心类 Virus
    微软企业库4.1学习笔记(七)创建对象 续集1 Virus
    微软企业库4.1学习笔记(五)对象创建和依赖注入方法 Virus
    微软企业库4.1学习笔记(十六)缓存模块4 服务器场中的缓存使用 Virus
    Android知识汇总
    移动UI研究学习汇总
    iOS独立存储Demo(调试过可以运行)
    The Official Preppy Handbook 目录
    一个好的App架构应该包括什么?
    转身再不仅仅只是开发人员
  • 原文地址:https://www.cnblogs.com/grimm/p/5389970.html
Copyright © 2011-2022 走看看