web - nginx禁止自動(dòng)轉(zhuǎn)換目錄為index.html
問(wèn)題描述
我有一個(gè)奇怪的用途.我用aria2做了個(gè)下載機(jī),用nginx做下載目錄的索引,autoindex已開(kāi),然而,如果我用aria2不小心下載了某個(gè)網(wǎng)站的首頁(yè)或者下載后保存為了index.html,當(dāng)我去訪問(wèn)這個(gè)下載目錄時(shí),會(huì)直接打開(kāi)index.html,我希望它永遠(yuǎn)不要自動(dòng)做這個(gè)事情,哪怕有index.html也不要去打開(kāi)它.我首先是把index去掉,發(fā)現(xiàn)根本無(wú)效,之前會(huì)自動(dòng)解析index.html的地方仍然會(huì)解析.于是我嘗試了index ;這樣一個(gè)參數(shù),發(fā)現(xiàn)nginx啟動(dòng)不起來(lái)會(huì)報(bào)錯(cuò).我現(xiàn)在希望做到只有訪問(wèn)根路徑/時(shí)會(huì)自動(dòng)選擇index.html顯示,而訪問(wèn)/down和/res下時(shí)會(huì)忽略掉index.html直接顯示目錄下的文件列表.以下是我對(duì)應(yīng)虛擬主機(jī)的設(shè)置:
# You may add here your# server {# ...# }# statements for each of your virtual hosts to this file### You should look at the following URL’s in order to grasp a solid understanding# of Nginx configuration files in order to fully unleash the power of Nginx.# http://wiki.nginx.org/Pitfalls# http://wiki.nginx.org/QuickStart# http://wiki.nginx.org/Configuration## Generally, you will want to move this file somewhere, and start with a clean# file but keep this around for reference. Or just disable in sites-enabled.## Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.##server {#listen 80; ## listen for ipv4; this line is default and implied#listen [::]:80 default_server ipv6only=on; ## listen for ipv6root /nginx;# Make site accessible from http://localhost/server_name localhost;# Exclude down&res directorylocation /down {try_files $uri $uri/ =404;alias /mnt/UDisk/;allow all;autoindex on;autoindex_format json;}location /res {try_files $uri $uri/ =404;alias /mnt/ResDisk/;allow all;autoindex on;autoindex_format json;}location = / {#index index.html;# First attempt to serve request as file, then# as directory, then fall back to displaying a 404.try_files $uri $uri/ / =404;# Uncomment to enable naxsi on this location# include /etc/nginx/naxsi.rules}#location /RequestDenied {# proxy_pass http://127.0.0.1:8080;#}#error_page 404 /404.html;# redirect server error pages to the static page /50x.html##error_page 500 502 503 504 /50x.html;#location = /50x.html {# root /usr/share/nginx/www;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000#location ~ .php$ {# fastcgi_split_path_info ^(.+.php)(/.+)$;# # NOTE: You should have 'cgi.fix_pathinfo = 0;' in php.ini## # With php5-cgi alone:# fastcgi_pass 127.0.0.1:9000;# # With php5-fpm:fastcgi_pass unix:/var/run/php5-fpm.sock;fastcgi_index index.php;include fastcgi_params;}# deny access to .htaccess files, if Apache’s document root# concurs with nginx’s one##location ~ /.ht {# deny all;#}}# another virtual host using mix of IP-, name-, and port-based configuration##server {# listen 8000;# listen somename:8080;# server_name somename alias another.alias;# root html;# index index.html index.htm;## location / {# try_files $uri $uri/ =404;# }#}# HTTPS server##server {# listen 443;# server_name localhost;## root html;# index index.html index.htm;## ssl on;# ssl_certificate cert.pem;# ssl_certificate_key cert.key;## ssl_session_timeout 5m;## ssl_protocols SSLv3 TLSv1;# ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP;# ssl_prefer_server_ciphers on;## location / {# try_files $uri $uri/ =404;# }#}
問(wèn)題解答
回答1:index sdafshdkfjlgydfgdf.html; 隨便改個(gè)不可能出現(xiàn)的名字
相關(guān)文章:
1. javascript - react如何獲取offsetX?2. python - sqlalchemy更新數(shù)據(jù)報(bào)錯(cuò)3. html5 - 前端面試碰到了一個(gè)緩存數(shù)據(jù)的問(wèn)題,來(lái)論壇上請(qǐng)教一下4. MySQL中無(wú)法修改字段名的疑問(wèn)5. macos - 無(wú)法source activate python276. PHPExcel表格導(dǎo)入數(shù)據(jù)庫(kù)怎么導(dǎo)入7. css - 移動(dòng)端 盒子內(nèi)加overflow-y:scroll后 字體會(huì)變大8. 運(yùn)行python程序時(shí)出現(xiàn)“應(yīng)用程序發(fā)生異常”的內(nèi)存錯(cuò)誤?9. html - 網(wǎng)頁(yè)的a標(biāo)簽到底要不要寫上域名?10. 我在導(dǎo)入模板資源時(shí)遇到無(wú)法顯示的問(wèn)題,請(qǐng)老師解答下

網(wǎng)公網(wǎng)安備