nginx配置yii2 URL重写规则

  1. server {  

  2.     listen       80;  

  3.     server_name  localhost;  

  4.   

  5.     #charset koi8-r;  

  6.     #access_log  /var/log/nginx/log/host.access.log  main;  

  7.   

  8.     location = /favicon.ico {  

  9.         log_not_found off;  

  10.         access_log off;  

  11.     }  

  12.     location = /robots.txt {  

  13.         allow all;  

  14.         log_not_found off;  

  15.         access_log off;  

  16.     }  

  17.   

  18.   

  19.     location / {  

  20.         try_files $uri $uri/ /index.php?$args;  

  21.         if (!-e $request_filename){  

  22.         rewrite ^/(.*) /index.php last;  

  23.         }  

  24.         root   /usr/share/nginx/html;  

  25.         index  index.php  index.html  index.htm;  

  26.     }  

  27.   

  28.     location ~ /(protected|framework|nbproject|themes/w+/views|index-test.php) {  

  29.         deny all;  

  30.         # for production  

  31.         internal;  

  32.         log_not_found off;  

  33.         access_log off;  

  34.     }  

  35.   

  36.   

  37.     #error_page  404              /404.html;  

  38.   

  39.     # redirect server error pages to the static page /50x.html  

  40.     #  

  41.     error_page   500 502 503 504  /50x.html;  

  42.     location = /50x.html {  

  43.         root   /usr/share/nginx/html;  

  44.     }  

  45.   

  46.     # proxy the PHP scripts to Apache listening on 127.0.0.1:80  

  47.     #  

  48.     #location ~ .php$ {  

  49.     #    proxy_pass   http://127.0.0.1;  

  50.     #}  

  51.   

  52.     # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000  

  53.     #  

  54.     location ~ .php$ {  

  55.         root           /usr/share/nginx/html;  

  56.         include  fastcgi_params;  

  57.         fastcgi_pass   127.0.0.1:9000;  

  58.         fastcgi_index  index.php;  

  59.         fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script_name;  

  60.        # include        fastcgi_params;  

  61.     }  

  62.   

  63.     # deny access to .htaccess files, if Apache's document root  

  64.     # concurs with nginx's one  

  65.     #  

  66.     #location ~ /.ht {  

  67.     #    deny  all;  

  68.     #}  

  69.   

  70.     # deny access to .htaccess files, if Apache's document root  

  71.     # concurs with nginx's one  

  72.     #  

  73.     location ~ /(.svn|.git|.ht|.DS) {  

  74.         deny all;  

  75.         internal;  

  76.     }  

  77. }  

  78. 新手要注意,网站根目录下是否有.htaccess 文件

原文链接:http://www.cnblogs.com/grimm/p/5389970.html

猜你喜欢

转载自itxiaozhuge.iteye.com/blog/2307415