2017-10-11 120 views
0

我有一个服务器(nginx/1.6.0 PHP 5.5.14)与这些设置工作正常。问题是当我使用location ^~ /sys/当我尝试访问sys文件夹时,它下载索引。如果我删除location ^~/sys /恢复正常工作。他错误只发生在PHP文件。 html文件正常工作。错误在哪里?Nginx的下载文件

server { 
    server_name site.com; 
    root /home/www/site.com; 
    index index.php index.html index.htm; 

    location/{ 
     index index.php index.html; 
     try_files $uri $uri/ /index.php; 
    } 

    location ~ [^/]\.php(/|$) { 
     fastcgi_pass unix:/data/php5514/var/run/php5-fpm.sock; 
     fastcgi_index index.php; 
     fastcgi_read_timeout 300; 
     include fastcgi_params; 
    } 

    location ^~ /sys/ { 
    } 
} 

我正在使用脚本,需要在nginx中执行此设置以保护文件夹免受未经授权的访问。

location ^~ /FOLDER/ { 
    if ($cookie_amember_nr !~* [a-zA-Z0-9]+) { #not authorized 
     rewrite ^(.*)$ http://EXAMPLE.COM/AMEMBER/protect/new-rewrite?f=FOLDERID&url=$request_uri?$args redirect; 
    } 
    set $file $document_root/AMEMBER/data/new-rewrite/$cookie_amember_nr-FOLDERID; 
    if (!-f $file) { #have not access 
     rewrite ^(.*)$ http://EXAMPLE.COM/AMEMBER/no-access/folder/id/FOLDERID?url=$request_uri?$args redirect; 
    }  
    #everything is ok 
} 

但是location^~这个问题不起作用。

+0

有关**专业服务器或网络相关基础架构管理**的问题,除非直接涉及编程或编程工具,否则无法用于堆栈溢出。您可以在[服务器故障](http://serverfault.com/about)上获得帮助。 – icecub

回答

0

你应该更详细地解释你的实际期望。

假设你要服务于/ SYS/PHP的内容,你还必须把fastcgi_pass块在此位置情况下,像这样:

location ^~ /sys/ { 
    fastcgi_pass unix:/data/php5514/var/run/php5-fpm.sock; 
    fastcgi_index index.php; 
    fastcgi_read_timeout 300; 
    include fastcgi_params; 
} 

如果这是你想要的东西,你会propably要使用upstream

upstream php { server unix:/data/php5514/var/run/php5-fpm.sock; } 

,并引用其作为

location ^~ /sys/ { 
    fastcgi_pass http://php; 
} 

ö ñ两个/所有位置块服务的PHP。

请记住,确切的位置匹配赢得较不准确/几乎匹配。也许你对/sys/something.php的GET请求不会被php-location块匹配,而是被/ sys-location块匹配。 无论如何,如果你不把某个东西放在那里就像一个不同的根一样,sys-location块有什么用处?

+0

我对/ sys /文件夹的期望是,当试图访问文件和子文件夹时,它不会返回文件下载。 –

+0

什么文件? PHP的? – roothahn