最近搜索

访问txt文件 nginx 配置

浏览:13
管理员 2025-10-20 20:24



nginx 配置访问某个txt文件



server {
  
        listen       443 ;
        server_name  file.cx111.cn;
        client_max_body_size 50M;
           ssl on;    
       root html;
       index index.html index.htm;
        #为虚拟主机指定pem格式的证书文件
        ssl_certificate      /etc/nginx/ssl/file.cx111.cn.pem;
        #为虚拟主机指定私钥文件
        ssl_certificate_key  /etc/nginx/ssl/file.cx111.cn.key;
  
        #ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  10m;
        #指定使用的ssl协议
  
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
        ssl_prefer_server_ciphers  on;
	    # 禁止访问的路径
    location ~ ^/(index|fileUpload) {
        return 403;
    }
     # 添加以下location规则以直接访问txt文件
    location ~* \.(txt)$ {
        root /usr/share/nginx/html;  # 确保与server块中的root一致
        try_files $uri =404;
    }
        location / {
            proxy_pass   http://117.72.168.145:8012;
        index index.html index.htm;
        }
}
server {
        listen       80;
        server_name  file.cx111.cn;
    rewrite ^(.*)$  https://$host$1 permanent;  
}

image.png







联系站长

站长微信:xiaomao0055

站长QQ:14496453