#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;
server_tokens off;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
# 在http段使用map限制域名,允许得设置变量为1,其他禁止访问设置为0
map $http_origin $allow_cros {
"~^(https?://(xx.test.com)?)$" 1;
"~^(http?://(x.x.x.x:8080)?)$" 1;
"~^\s" 1;
"~*" 0;
}
server {
listen 8080;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
# 在server段将禁止访问域直接返回403
if ($allow_cros = 0) {
return 403;
}
location / {
root /usr/local/nginx/html;
index index.html index.htm;
}
location /api/ {
proxy_pass http://x.x.x.x:9000/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
}
}
通过nginx配置从前端解决cros漏洞
原创li371573016 博主文章分类:nginx ©著作权
©著作权归作者所有:来自51CTO博客作者li371573016的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
从前端信息泄露进行漏洞挖掘
从前端信息泄露进行漏洞挖掘前言在漏洞挖掘中,比的不但是资产收集的本领,更多的是细心。往往毫不起眼的前端文件,
上传 服务器 静态资源 静态文件 -
从前端到未来,前端发展闲聊
1. 前情提要毋庸讳言,在我刚工作的时候,前端是还是一个不受重视的岗位。切
前端 展望 前端开发 技术栈 php -
nginx 前端代理配置解决跨域问题
前端配置代理(解决跨域问题)server { listen 80; server_name www.xxxx.org xxxxx.org;
nginx javascript html xml