nginx.conf 配置中有个漏洞,那就是没有配置哪些目录是不允许直接访问的,在传统tomcat作为服务器的时候,tomcat本身的机制就禁止直接访问WEB-INF下的内容,但是在nginx中,由于配置了部分内容直接从nginx转发出去,这就导致了WEB-INF目录实际上可能会被暴露出去,一旦暴漏了,那么系统架构,源代码,数据库配置文件,系统配置文件等内容将一并泄露,这对于商业项目来讲会是致命的安全隐患,再次提醒自己以及相关人士,一定要配置不允许访问的目录。
为此,必须在nginx.conf中配置上不允许访问的网站目录。
不允许访问配置方式如下:
location ~ ^/(WEB-INF|META-INF)/{
deny all;
}
一个完整的nginx.conf例子:
user root; 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 10240; } 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_min_length 1k; gzip_buffers 16 64k; gzip_http_version 1.1; gzip_comp_level 2; gzip_types application/json text/plain text/css; gzip_vary on; fastcgi_intercept_errors on; upstream tomcat_server { server 127.0.0.1:8080; # server 127.0.0.1:8081; # server 127.0.0.1:8082; } ############################ ######## server start #### ############################ server { listen 80; server_name www.xxx.com; root /data/www/www.xxx.com; location /{ index index.htm index.html index.jsp; } location ~ ^/(WEB-INF|META-INF)/{ deny all; } location ~ \.(jsp|do)?$ { proxy_set_header Host $host:80; proxy_set_header X-Forwarded-For $remote_addr; proxy_pass http://tomcat_server; } location ~ .*\.(js|css|gif|jpg|jpeg|png|bmp|swf)$ { expires 24h; } if (!-e $request_filename){ rewrite "^/a/eg/([0-9]+)/([0-9]+)/([0-9]+)$" /api/eventlog.do?game_id=$1&platform_id=$2&channel_id=$3 last; rewrite "^/games/game_([0-9]+)\.html$" /games/game_show.jsp?id=$1 last; rewrite "^/games/page_([0-9]+)\.html$" /games/index.jsp?p=$1 last; rewrite "^/games/category_([0-9]+)\.html$" /games/index.jsp?c=$1 last; rewrite "^/games/category_([0-9]+)/page_([0-9]+)\.html$" /games/index.jsp?c=$1&p=$2 last; rewrite "^/blogs/blog_([0-9]+)\.html$" /blogs/blog_show.jsp?id=$1 last; rewrite "^/blogs/page_([0-9]+)\.html$" /blogs/index.jsp?p=$1 last; rewrite "^/blogs/category_([0-9]+)\.html$" /blogs/index.jsp?c=$1 last; rewrite "^/blogs/category_([0-9]+)/page_([0-9]+)\.html$" /blogs/index.jsp?c=$1&p=$2 last; rewrite "^/links/category_([0-9]+)\.html$" /links/index.jsp?c=$1 last; } } ############################ ######## server end #### ############################ }
相关推荐
首先建立下面的配置文件放在nginx的conf目录下面,命名为blocksip.conf: deny 95.105.25.181; 保存一下。 在nginx的配置文件nginx.conf中加入:include blocksip.conf; 重启一下nginx的服务:/usr/local/nginx/sbin/...
# 使用说明 解压到固定目录不用随意修改路径,如果需要修改路径请修改注册表系统路径! 开始菜单允许 regedit 找到 【HKEY_CURRENT_USER\Software\WebServer】 去设置服务器...需要自己绑定和nginx虚拟目录进行访问
在nginx的配置文件nginx.conf文件的server节点中,添加一个location,示例如下: location /your url { return 403; } 这里具体以nginx自带nginx.conf为例,屏蔽根URL路径/: 屏蔽前 location / { root html; ...
3.这里只需要修改Nginx的配置,让它通过tomcat来转发,所以我们在这一步只需要在nginx.conf中添加几行代码就行。 如果看不懂 。建议直接拿我替来用。 Copy下面的内容 替换 你的nginx.conf注意黄色端口要改为你的。 ...
4.允许访问日志?这将记录所有网络请求。 不记录选择“n”。 请输入新的虚拟主机的访问日志名称,默认的访问日志名称: (直接按回车) 可以自定义虚拟主机的目录。 5.开启 Rewrite 规则? 不使用选择“n” 只有Discuz...
在Nginx的conf目录下修改nginx.conf或者vhost下对应的domain conf,添加以下代码: 代码如下:location ~* \.(eot|ttf|woff)$ {add_header Access-Control-Allow-Origin *;} 更详细的Nginx的跨域配置,请查看下面的...
bg-ansible 一种在添加新版本的应用程序的同时使网络应用程序的停机时间为零的... 第四步完成ins-and-conf.yml剧本,并设置安装docker和所需的系统软件包以及防火墙配置,包括允许访问tcp端口3000和OpenSSH的步骤。
安装 nginx 后,将您的配置(例如 /etc/nginx/nginx.conf 文件)替换为存储库中的配置,打开它,并调整感叹号后面的行。 cd进入后端目录并执行node index.js以启动服务器。 现在您的服务器应该在可用。 尝试打开 ...
另外如果h5想要跨域的话,可以配置你要访问的那个资源所在的服务,这里以 nginx 为例 修改 nginx.conf 文件, 在location 下 添加 add_header 相关配置 location / { root html; index index.html index.htm; add...
这些subfolder将允许访问服务 subdomain这些将允许访问服务 要启用反向代理配置: 配置您的默认站点配置 确保您的默认站点配置在适当的位置包含以下行,如默认版本所示: 对于子文件夹方法: include /config/...
注意语法有错将影响网站的访问. Pn 文件夹里带有 Discuz 和 SupeSite 的 Rewrite 规则, 建议直接使用! Pn\dz.htaccess.zip Discuz 的规则, 解压到 Discuz 目录即可; Pn\ss.htaccess.zip SupeSite 的规则, 解压...
ngx_wpt ngx_wpt 是 NGINX 的一个插件,可将其扩展为能够在多个服务器之间路由 WebPageTest 实例的传入流量,从而允许 WPT 扩展水平。特征非常快速的反向代理和负载均衡器(感谢 NGINX) ngx_wpt 配置的零停机重新...
在不同的项目中可以使用不同的版本-这种情况不允许 添加配置文件 写测试代码 如下图: 结论: ~将原来的原始的项目,变成maven项目 ~相同的代码,不同的环境,将项目跑起来 5.4.添加Mybatis 将service折成了两个...
fetchheaders 是一个 python 脚本,它使用多个线程同时(使用多个线程)以安全的方式(通过端口 443 使用 SSL)访问 imap 服务器上的多个电子邮件帐户。 这个脚本的主要目的是获取和显示头信息; 特别是电子邮件的...
访问控制列表和外观(主题) 添加其他服务器软件及其各自的GUI页面创建新的身份验证方法以在其他子系统中使用提供其他类型的设备和防火墙接口引入其他软件包,这些软件包将自动更新通过其他工作任务来增强后端服务...