nginx alias 无法解析php的解决办法(附带一些nginx基本设置)

10 篇文章 0 订阅

server
    {
        listen 80;  #端口号
        server_name www.domain.com;   #域名
        index index.html index.htm index.php index.shtml;  #默认首页
        root  /var/www/html;  #网站根目录
        charset gbk;    #默认编码

        location /public/  #设定要重写的目录名
        {
                alias /var/www/public/; #重定向目的目录。

                #例:如果用户访问http://www.domain.com/public/test.html 不会访问/var/www/html/public/test.html,而访问的是/var/www/public/test.html,虽然这个文件并没有在域名目录下
        }

#做完上面的设置后,我们发现访问PHP文件http://www.domain.com/public/test.php时,还是去访问了/var/www/html/public/test.php,也就是说访问php文件没有起到重定向的作用,所以我们还要配置如下这段

#start

        location ~ ^/public/.+\.php$
        {
                root /var/www/html/web/news/public;
                rewrite /public/(.*\.php?) /$1 break;
                include fastcgi.conf;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
        }

#end

        location ~ .*\.(php|php5)?$
        {
            #fastcgi_pass  unix:/tmp/php-cgi.sock;
            fastcgi_pass  127.0.0.1:9000;
            fastcgi_index index.php;
            #include fcgi.conf;
            include fastcgi.conf;
            rewrite  ^/([a-zA-Z]+)\/([a-zA-Z]+)$ /$2.shtml last;
        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;  #缓存30天
        }

        location ~ .*\.(js|css)?$
        {
            expires      1h; #缓存1个小时
        }

        access_log  /var/log/domain.log  access;  #定义日志文件
        ssi on;
        ssi_silent_errors on;
        ssi_types text/shtml;
    }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值