我有以下nginx配置:
location ~ ^/system/filedir/scripts {
autoindex on;
}
location ~ ^/filedir/scripts {
alias /system/filedir/scripts/;
}
当我访问http://myserver.com/system/filedir/scripts
时,一切正常,我可以看到脚本目录中包含的文件列表。
但是当我访问http://myserver.com/filedir/scripts
时,我遇到以下错误:
[error] 2083#0: *83335 "/system/filedir/index.html" is not found (2: No such file or directory), request: "GET /filedir/scripts/ HTTP/1.1"
我无法摆脱index.html的添加并获取文件列表。 如果我尝试
,也会发生同样的事情 location ~ ^/filedir/scripts {
root /system/;
}
这是我的nginx.conf:
# daemon off;
# user nobody;
worker_processes 1;
error_log logs/error.log;
# error_log logs/error.log notice;
# error_log logs/error.log info;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
gzip_http_version 1.0;
gzip_proxied any;
gzip_min_length 500;
gzip_disable "MSIE [1-6]\.";
gzip_types text/plain
text/html
text/xml
text/css
text/comma-separated-values
text/javascript application/x-javascript
application/atom+xml
application/json
application/xml
application/rss+xml
image/svg+xml
application/vnd.ms-fontobject
application/x-font-ttf;
include my_sites/*;
}
答案 0 :(得分:1)
您可以使用重写:
server {
location ~ ^/system/filedir/scripts/ {
autoindex on;
}
location ~ ^/filedir/scripts/ {
rewrite ^/filedir/scripts/(.*)$ /system/filedir/scripts/$1 last;
}
或者是proxy_pass:
server {
resolver 8.8.8.8;
location ~ ^/system/filedir/scripts/ {
autoindex on;
}
location ~ ^/filedir/scripts/ {
proxy_pass http://$host/system/$uri;
}
我尝试过使用别名root的组合,但它们都失败了。