当前位置:首页 > Liunx教程 >

lnmp伪静态_lnmp伪静态设置方法

发布时间:2019-12-19 09:12:56 作者:佚名 阅读:(315)

最近朋友在搭建服务器的时候建议使用的lnmp的,在搭建好之后问lnmp伪静态的设置方法,接下来吾爱编程为大家介绍一下lnmp伪静态设置方法的设置方法,有需要的小伙伴可以参考一下:

我们在使用lnmp vhost add添加好网站之后,会在目录/usr/local/nginx/conf/vhost下面生成一个对应的配置文件,这里我的是www.itbiancheng.com.conf,添加不同的域名会生成不同的配置文件,这样可以方便的管理每个网站,避免多个网站都放在一个文件里面不好管理。

1、打开配置文件,代码如下:

server
    {
        listen 80;
        server_name www.itbiancheng.com ;
        index index.html index.htm index.php default.html default.htm default.php;
        root  /data/www/www.itbiancheng.com;
        include rewrite/other.conf;
        include enable-php-pathinfo.conf;
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }
        location ~ /.well-known {
            allow all;
        }
        access_log off;
    }

2、加入我们自己相对应的规则:

if (!-e $request_filename)
	   {	
		rewrite ^/([a-zA-Z0-9]+)$ /$1/ permanent;
		rewrite  ^/report\.html$ /index.php?c=dingshi&a=report last;
		rewrite  ^/getHit\.html$ /index.php?c=dingshi&a=getHit last;
		rewrite ^/search\.html$ /index.php?c=index&a=search last;
		rewrite ^/(xinwen|gonglue)/$ /index.php?c=news&a=index&cat=$1 last;
		rewrite ^/(xinwen|gonglue)/list_(\d+)_(\d+)\.html$ /index.php?c=news&a=index&cat=$1&tid=$2&page=$3 last;
		rewrite ^/(xinwen|gonglue)/(\d+)\.html$ /index.php?c=news&a=show&cat=$1&id=$2 last;
		rewrite ^/(xinwen|gonglue)/(\d+)_(\d+)\.html$ /index.php?c=news&a=show&cat=$1&id=$2&page=$3 last;
	   }

完整的规则如下:

3、校验规则,然后重启服务:

nginx -t //校验规则是否正确
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successfu
提示成功的话 重启nginx即可
service nginx restart
如果报错可能是添加有误或伪静态规则有误。

以上就是吾爱编程为大家介绍的lnmp伪静态设置方法。

欢迎分享转载→ lnmp伪静态_lnmp伪静态设置方法

© 2015-2021 - 吾爱编程网 版权所有 苏ICP备18033726号-1关于我们 - 网站声明 - 联系我们