sinykk 发表于 2013-2-7 01:33:30

nginx 配置相关 URL重写, 自定义404错误页面

NGINX禁止与允许IP访问服务
 
location / {
            allow  122.234.54.116;
            deny   all;
            index  index.html index.htm index.php;
            if (!-e $request_filename){
                rewrite ^(.*)$ /index.php?s=$1 last;
                break;
            }
        }
 
 
装了NGINX1.0.8 不能访问PHP文件
 
这个主要是PHP的解析脚本路径找不到
 
location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
 
 
 
NGINX下如何自定义404页面

IIS和APACHE下自定义404页面的经验介绍文章已经非常多了,NGINX的目前还比较少,为了解决自家的问题特地对此作了深入的研究。研究结果表明,NGINX下配置自定义的404页面是可行的,而且很简单,只需如下几步:

1.创建自己的404.php页面

2.更改nginx.conf在http定义区域加入: fastcgi_intercept_errors on;

3.更改nginx.conf(或单独网站配置文件,例如在nginx -> sites-enabled下的站点配置文件 )

中在server 区域加入: error_page 404 = /404.php;  或者 error_page 404 = http://www.xxx.com/404.html;
 
=================================================
 
让Nginx支持shtml格式

发现包括IIS在内的大多数处理服务器,都是默认不支持shtml的,nginx支持shtml的方法为:
在nginx.conf配置文件,添加:
<img style="margin: 0px; padding: 0px; border-style: none;" alt="">ssi on;
ssi_silent_errors on;
ssi_types text/shtml;
然后保存,重启nginx即可。
页: [1]
查看完整版本: nginx 配置相关 URL重写, 自定义404错误页面