我正在查看几个文档,但由于某些原因,我无法理解我所要做的配置。基本上我想:
所有目录请求都应保留其url,但应由
我尝试过设置.php处理的位置,但我永远也找不出如何使它正常工作。我将继续做下去,但也希望能得到一些快速的帮助:)
谢谢!
编辑2:我想我想出了一些像样的东西。它可能不是完美的,但它应该有效。
server {
listen 80;
server_name _;
server_tokens off;
root /mypath/www;
access_log /mypath/access.log;
error_log /mypath/error.log;
index index.html;
location ^~ /app {
return 404;
}
location ~ \.conf {
return 404;
}
location ~ \.php {
return 404 ;
}
location ~ /images/.*.(jpg|jpeg|png|gif) {
try_files $uri $uri = 404;
expires max;
}
location ~ /css/.*.css {
try_files $uri $uri = 404;
expires 1d;
}
location ~ /js/.*.js {
try_files $uri $uri = 404;
expires 1d;
}
location / {
try_files $uri @PHPProxy;
error_page 500 501 502 503 504 505 $document_root/error.html;
}
location @PHPProxy {
include fastcgi_params;
fastcgi_pass unix:/tmp/php.socket;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
}
}发布于 2012-03-05 03:33:56
想起来挺有趣的。我以前只是确保阻止目录或确保我没有任何文件,我不希望被访问在我的文档根目录。
我想我找到办法了。它实际上并没有为其他文件提供404或403,它只是将除指定目录之外的所有内容重写到/index.php。
下面是我用它测试的配置:
server {
listen 80;
listen your.domain.name:80;
server_name your.domain.name;
root /var/www/vhost/testing;
server_tokens off;
location ~ ^/(images|css|js)/.* {
expires max;
}
location / {
index index.php;
rewrite ^(.*)$ /index.php$1 last;
}
location ~ ^/index.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param PATH_INFO $fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
}因此,/images、/css或/js中的任何内容都只是加载,但其他所有内容都会重写到索引文件中。
请记住,没有在这3个文件夹中的任何文件都将被完全忽略。
https://stackoverflow.com/questions/9560979
复制相似问题