yii2 URL重写 nginx的配置
Url的重写
nginx的配置文件
- [root@localhost protected]# vim /etc/nginx/conf.d/default.conf
- server {
- listen 80;
- server_name localhost;
- #charset koi8-r;
- #access_log /var/log/nginx/log/host.access.log main;
- location = /favicon.ico {
- log_not_found off;
- access_log off;
- }
- location = /robots.txt {
- allow all;
- log_not_found off;
- access_log off;
- }
- location / {
- try_files $uri $uri/ /index.php?$args;
- if (!-e $request_filename){
- rewrite ^/(.*)$ /index.php?r=$1 last;
- }
- root /usr/share/nginx/html;
- index index.php index.html index.htm;
- }
- location ~ /(protected|framework|nbproject|themes/\w+/views|index-test\.php) {
- deny all;
- # for production
- internal;
- log_not_found off;
- access_log off;
- }
- #error_page 404 /404.html;
- # redirect server error pages to the static page /50x.html
- #
- error_page 500 502 503 504 /50x.html;
- location = /50x.html {
- root /usr/share/nginx/html;
- }
- # proxy the PHP scripts to Apache listening on 127.0.0.1:80
- #
- #location ~ \.php$ {
- # proxy_pass http://127.0.0.1;
- #}
- # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
- #
- location ~ \.php$ {
- root /usr/share/nginx/html;
- include fastcgi_params;
- fastcgi_pass 127.0.0.1:9000;
- fastcgi_index index.php;
- fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
- # include fastcgi_params;
- }
- # deny access to .htaccess files, if Apache's document root
- # concurs with nginx's one
- #
- #location ~ /\.ht {
- # deny all;
- #}
- # deny access to .htaccess files, if Apache's document root
- # concurs with nginx's one
- #
- location ~ /(\.svn|\.git|\.ht|\.DS) {
- deny all;
- internal;
- }
- }
yii的配置文件
- /project/protected/config/main.php
- <?php
- // uncomment the following to define a path alias
- // Yii::setPathOfAlias('local','path/to/local-folder');
- // This is the main Web application configuration. Any writable
- // CWebApplication properties can be configured here.
- return array(
- 'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
- 'name'=>'My Web Application',
- // preloading 'log' component
- 'preload'=>array('log'),
- // autoloading model and component classes
- 'import'=>array(
- 'application.models.*',
- 'application.components.*',
- ),
- 'modules'=>array(
- // uncomment the following to enable the Gii tool
- /*
- 'gii'=>array(
- 'class'=>'system.gii.GiiModule',
- 'password'=>'Enter Your Password Here',
- // If removed, Gii defaults to localhost only. Edit carefully to taste.
- 'ipFilters'=>array('127.0.0.1','::1'),
- ),
- */
- ),
- // application components
- 'components'=>array(
- 'user'=>array(
- // enable cookie-based authentication
- 'allowAutoLogin'=>true,
- ),
- // uncomment the following to enable URLs in path-format
- 'urlManager'=>array(
- 'urlFormat'=>'path',
- 'showScriptName' => false,
- 'urlSuffix' => '.html',
- 'rules'=>array(
- '<controller:\w+>/<id:\d+>'=>'<controller>/view',
- '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
- '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
- ),
- ),
- // database settings are configured in database.php
- 'db'=>require(dirname(__FILE__).'/database.php'),
- 'errorHandler'=>array(
- // use 'site/error' action to display errors
- 'errorAction'=>'site/error',
- ),
- 'log'=>array(
- 'class'=>'CLogRouter',
- 'routes'=>array(
- array(
- 'class'=>'CFileLogRoute',
- 'levels'=>'error, warning',
- ),
- // uncomment the following to show log messages on web pages
- /*
- array(
- 'class'=>'CWebLogRoute',
- ),
- */
- ),
- ),
- ),
- // application-level parameters that can be accessed
- // using Yii::app()->params['paramName']
- 'params'=>array(
- // this is used in contact page
- 'adminEmail'=>'webmaster@example.com',
- ),
- );
重启nginx
- [root@localhost protected]# service nginx restart
- 停止 nginx: [确定]
- 正在启动 nginx: [确定]
yii2 URL重写 nginx的配置的更多相关文章
- 【URL重写】IIS7配置URL重写
URL Rewrite Module 此模块适用于IIS7.7.5.8. 微软在IIS7中添加了URL的重写模块,并且免费使用,可以导入.htaccess规则,但需要安装. 第一步:安装URL2. ...
- ASP.NET伪静态 UrlRewrite(Url重写) 实现和配置
核心提示:大家一定经常在网络上看到很多网站的地址后缀都是用XX.HTML或者XX.ASPX等类似静态文件的标示来操作的吧,那么大家有怀疑过他真的是一个一个的静态生成的文件么,静态文件的生成的优缺有好有 ...
- url重写(伪静态)IIS配置图解
通过IIS创建虚拟目录,新建网站放在该目录下面: IIS配置: 虚拟目录=>点击右键=>选择属性: 点击配置: 点击编辑: 复制两个文本框文本到记事本中=>点击确定: 点击添加=&g ...
- centos7 Apache开启URL重写组件并配置.htaccess实现伪静态
第一.修改httpd.conf文件 A - 在etc/httpd/conf/目录下的httpd.conf 文件,找到: LoadModule rewrite_module modules/mod_re ...
- Nginx配置虚拟机,url重写,防盗链
配置目录: · 虚拟主机 · PHP支持 · URL重写 · 防止盗链 · 持续更新… 一.虚拟主机 1.创建 文件格式:{域名}.conf 具体如下: $ s ...
- (转)nginx下基于ThinkPHP框架的网站url重写
nginx下基于ThinkPHP框架的网站url重写nginx下的基于thinkphp的应用的url重写,需了解thinkphp的各种url格式参数的处理逻辑以及nginx重写的原理.简单点说,无论哪 ...
- nginx的URL重写应用实例
1,NGINx的URL重写 NGINX 的URL重写模块用的比较多,主要使用的命令有if rewrite set break 2 if命令 语法如下"" 语法:if(conditi ...
- asp.net 页面url重写
不更改情况下,页面路径为index.aspx?id=1,现在输入页面路径index/1时,也能访问到页面,这一过程叫做url重写 ①:在一个类里制定路径重写规则,以下为自定义UrlRewriterFi ...
- 转载MSDN 在ASP.NET 中执行 URL 重写
转载文章原网址 http://msdn.microsoft.com/zh-cn/library/ms972974.aspx 摘要:介绍如何使用 Microsoft ASP.NET 执行动态 URL 重 ...
随机推荐
- phpstorm+xdebug详解
1.run->edit configurations StartUrl最好是网址,不然容易出错,Server选择的是配置时添加的Servers,详可参考:http://www.cnblogs.c ...
- 6.flume实战(三)※
需求:将A服务器上的日志实时采集到B服务器上面去 大致原理: 技术选型: exec source + memory channel + avro sink avro source + memory c ...
- 《JavaScript模式》精要
P25. 如何避免eval()定义全局变量? 如: var jsstring = "var un = 1;"; eval(jsstring); console.log(typeof ...
- DRF视图集的路由设置
在使用DRF视图集时,往往需要配一大堆路由,例如: # views.py class DepartmentViewSet(ListModelMixin,CreateModelMixin,Retriev ...
- poj 1696(极角排序)
Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3924 Accepted: 2457 Descrip ...
- Centos 7.3 安装 Mongodb
通过yum 安装: yum install -y mongodb-server Mongodb操作命令: #启动 systemctl start mongod.service #关闭 systemct ...
- Spring Mvc中@ResponseBody中文乱码解决,以及修改返回的Content-Type
http://www.codeif.com/topic/784 spring 3 mvc 的 @ResponseBody返回数据用起来很方便,但是中文乱码,而且返回的Content-Type不带编码信 ...
- ASP.NET中怎样将页面设为首页,加入收藏
1.文字js脚本事件:<span onClick="var strHref=window.location.href;this.style.behavior=’url(#default ...
- [centos6.5] 完全卸载httpd mysql php
rpm -qa|grep mysql # 列出所有mysql相关包 rpm -e 包名 # 逐一卸载,一个方便技巧是:卸载时可以不带版本,比如 # mysqlclient10-3.23.58-4.RH ...
- HDU 6330.Problem L. Visual Cube-模拟到上天-输出立方体 (2018 Multi-University Training Contest 3 1012)
6330.Problem L. Visual Cube 这个题就是输出立方体.当时写完怎么都不过,后来输出b<c的情况,发现这里写挫了,判断失误.加了点东西就过了,mdzz... 代码: //1 ...