# DO NOT RESPOND TO REQUESTS OTHER THAN yourdomain.com
server {
listen 80 default;
server_name _;
return 444;
}
# FILE UPLOADS
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
access_log /var/log/nginx/s3uploadproxy.access.log;
error_log /var/log/nginx/s3uploadproxy.error.log;
proxy_read_timeout 10;
proxy_connect_timeout 10;
# allow big files...
client_max_body_size 30M;
# and slow uploads
proxy_send_timeout 1200;
# Deny illegal Host headers
if ($host !~* ^(yourdomain.com|www.yourdomain.com)$ ) {
return 444;
}
# dissalow methods
if ($request_method !~ ^(OPTIONS|POST)$ ) {
# empty response
return 444;
}
location / {
# CORS PRE-FLIGHT REQUESTS
if ($request_method = 'OPTIONS') {
more_set_headers 'Access-Control-Allow-Origin: *';
more_set_headers 'Access-Control-Allow-Methods: POST, OPTIONS';
more_set_headers 'Access-Control-Max-Age: 1728000';
more_set_headers 'Content-Type: text/plain; charset=UTF-8';
#more_set_headers 'Access-Control-Allow-Headers: ';
return 200;
}
# FILE UPLOADS
if ($request_method = 'POST') {
more_set_headers 'Access-Control-Allow-Origin: *';
proxy_pass http://your-s3-bucket;
}
}
# 204 (No Content) for favicon.ico
location = /favicon.ico {
#empty_gif;
return 204;
}
}
Nginx 跨域配置示例
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 最近连续两个朋友问我跨域相关问题,我猜想可能不少朋友也遇到类似问题,我打算写个博客聊一下我实际使用的配置, 先说明...
- 注意: nginx 不支持循环if add_header xxxxx xxxx 内容请放入location内,直接...
- 前言 学完vue,就想搞点前后端分离玩玩,然而在请求路径的时候却出现了跨域问题!因此我就想解决一下!开搞 1.前端...