nginx 站点使用try_files配置案例

支持thinkphp 伪静态
或者 URL链接是 index.php?s=xxxxx的,当然也可以改成你自己,只要修改try_files $uri $uri/ /index.php?s=$uri&$args;此处就可以了

文件名lanmps.com.conf
风.fox
内容如下

server {
    #侦听80端口
    listen       80;
    #定义使用 lanmps.com访问
    server_name  lanmps.com;
    #定义服务器的默认网站根目录位置
    root /www/wwwroot/default;
    index index.html index.htm index.php;
    #默认请求
    location / {
        #定义首页索引文件的名称
        #index index.html index.htm index.php;
        try_files $uri $uri/ /index.php?s=$uri&$args;
    }
    # 定义错误提示页面
    error_page   500 502 503 504 /50x.html;
        location = /50x.html {
    }
    # 加载伪静态配置 或自定义配置
    #include /www/wwwroot/default/lanmps-*.conf;

    #静态文件,nginx自己处理
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|json|swg)?$ {
            #过期30天,静态文件不怎么更新,过期可以设大一点,
            #如果频繁更新,则可以设置得小一点。
            expires      30d;
    }
    location ~ .*\.(js|css)?$ {
            #过期12小时,静态文件不怎么更新,过期可以设大一点,
            expires      12h;
    }
    #PHP 脚本请求全部转发到 FastCGI处理. 使用FastCGI默认配置.
    location ~ ^.+\.php {
        try_files $uri =404;
        #fastcgi_pass  unix:/tmp/php-cgi.sock;
        #fastcgi_pass   127.0.0.1:9950;
        # bakend 在 upstream.conf 文件中
        fastcgi_pass   bakend;
        fastcgi_index  index.php;
        fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
        fastcgi_param  PATH_INFO          $fastcgi_path_info;
        include        fastcgi.conf;
    }
    #禁止访问 .htxxx 文件
    location ~ /.ht {
        deny all;
    }
    #设定本虚拟主机的访问日志
    access_log  /www/wwwLogs/localhost.log access;
}

upstream.conf
内容如下

upstream bakend {
    ip_hash;
    server 127.0.0.1:9950 weight=1 max_fails=1 fail_timeout=0s;
    #server 127.0.0.1:9951 weight=1 max_fails=1 fail_timeout=0s;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

风.foxwho

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值