#user nobody;

user sam owner;

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; sendfile on;
#tcp_nopush on; #keepalive_timeout 0;
keepalive_timeout 65; #gzip on; server {
# listen 80;
listen 9000;
server_name localhost;
# server_name resouce; # 以文件目录的方式展开
autoindex on; #charset koi8-r; #access_log logs/host.access.log main; # location / {
# # root html;
# root D:\Dev\www;
# index index.html index.htm; # # 跨域
# add_header 'Access-Control-Allow-Origin' '*'; # # 每次访问, 不缓存
# add_header Cache-Control 'no-cache, must-revalidate';
# } # location /{
# root D:\Dev\www;
# index index.html index.htm;
# proxy_pass http://localhost:9000/; # #告诉浏览器允许跨域访问的方法
# add_header Access-Control-Allow-Methods *;
# # 告诉浏览器缓存OPTIONS预检请求1小时
# add_header Access-Control-Max-Age 3600;
# #允许带有cookie访问
# add_header Access-Control-Allow-Credentials true;
# #注意 * 不能满足带有cookie的访问,Origin 必须是全匹配,这里通过变量获取
# add_header Access-Control-Allow-Origin $http_origin;
# #设置支持所有的自定义请求头
# add_header Access-Control-Allow-Headers $http_access_control_request_headers;
# #如果预检请求,则返回成功,不需要转发到后端
# if ($request_method = OPTIONS){
# return 200;
# }
# } # location / {
# root D:\Dev\www;
# index index.html index.htm;
# proxy_pass http://192.168.31.193:8081;
# proxy_set_header Host $host:9000;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# } location / {
root D:\Dev\www;
index index.html index.htm;
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
#
# Custom headers and headers various browsers *should* be OK with but aren't
#
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
#
# Tell client that this pre-flight info is valid for 20 days
#
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain; charset=utf-8';
add_header 'Content-Length' 0;
return 204;
}
if ($request_method = 'POST') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
}
if ($request_method = 'GET') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
}
} #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 html;
root D:\Dev\www;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# 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; # location / {
# root html;
# index index.html index.htm;
# }
#} # HTTPS server
#
# server {
# listen 3000;
# server_name resouce;
# # 以文件目录的方式展开
# autoindex on;
# location / {
# root D:\Dev\www;
# # 跨域
# add_header Access-Control-Allow-Origin *;
# # 每次访问, 不缓存
# add_header Cache-Control 'no-cache, must-revalidate';
# } # ssl_certificate cert.pem;
# ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on; # location / {
# root html;
# index index.html index.htm;
# }
#}

}

nginx.config 多个方案解决跨域问题的更多相关文章

  1. nginx代理天地图做缓存解决跨域问题

    作为一个GISer开发者,天地图是经常在项目中以底图的形式出现,其加载地址如: 天地图矢量:http://t{0-6}.tianditu.com/DataServer?T=vec_w&x={x ...

  2. nginx反向代理ajax,解决跨域问题

    server { listen 8000; server_name somename alias another.alias; location /a { add_header 'Access-Con ...

  3. 前端通过Nginx反向代理解决跨域问题

    在前面写的一篇文章SpringMVC 跨域,我们探讨了什么是跨域问题以及SpringMVC怎么解决跨域问题,解决方式主要有如下三种方式: JSONP CORS WebSocket 可是这几种方式都是基 ...

  4. nginx反向代理解决跨域问题

    跨域:浏览器从一个域名的网页去请求另一个域名的资源时,域名.端口.协议任一不同,都是跨域 . 下表格为前后端分离的域名,技术信息:   域名 服务器 使用技术 前端 http://b.yynf.com ...

  5. 【Nginx】使用Nginx如何解决跨域问题?看完这篇原来很简单!!

    写在前面 当今互联网行业,大部分Web项目基本都是采用的前后端分离模式.前端为H5项目,后端为Java.PHP.Python等项目.而且大部分后端服务并不会只部署一套服务,而是会采用Nginx对后端服 ...

  6. springBoot工程解决跨域问题

    更新:通过一个 @CrossOrigin  注解就可以完美解决跨域问题. 创建一个配置类 package com.miaoshaProject.configuration; import org.sp ...

  7. 14 微服务电商【黑马乐优商城】:day06-使用nginx反向代理并掌握cors解决跨域

    本项目的笔记和资料的Download,请点击这一句话自行获取. day01-springboot(理论篇) :day01-springboot(实践篇) day02-springcloud(理论篇一) ...

  8. Nginx解决跨域问题(CORS)

    跨域 解决跨域问题一般有两种思路: CORS 在后端服务器设置 HTTP 响应头,把你需要运行访问的域名加入加入 Access-Control-Allow-Origin中. jsonp 把后端根据请求 ...

  9. windows环境下 nginx+iis 反向代理解决跨域问题

    项目基本完成,是时候花点时间整理一下最近的姿势了 1 什么是跨域? 网上对于跨域的概念会有大篇幅的文章去解释,似乎有点玄乎,初学者很容易对这个概念产生恐惧,跨域其实很简单,其实只要知道一点,无法跨域访 ...

随机推荐

  1. idea工程在maven projects中显示灰色的解决办法

    原文链接:https://blog.csdn.net/qq_30507287/article/details/83515461 在Mac上使用idea进行开发的过程中,一般在MavenProject中 ...

  2. 第1章 Spark SQL概述

    第1章 Spark SQL概述 1.1 什么是Spark SQL Spark SQL是Spark用来处理结构化数据的一个模块,它提供了一个编程抽象叫做DataFrame并且作为分布式SQL查询引擎的作 ...

  3. golang安装及vscode编辑器配置

    安装Go语言及搭建Go语言开发环境 下载 下载地址:https://studygolang.com/dl 系统选择: 根据不同系统下载安装包: 安装 Windows MAC安装 点开可执行程序 下一步 ...

  4. ansible实现批量建立互信

    Ansible:自动化运维工具 为什么要建立互信:ansible批量配置管理的前提是管理机和被管理机ssh互信,即通过将管理主机的公钥(id_rsa.pub)添加到目标主机上,实现管理机不通过交互式输 ...

  5. python中a, b = a, a + b这条语句是如何执行的?

    a,b=b,a+b,这条语句在"理解"上还是与C语言有些差别的.在Python中,可以做下面的方式理解:首先,把等号右边的算式分别算完再说,然后按照一一对应的关系把值赋给等号左边的 ...

  6. Mac本软件安装之后打不开的解决办法

    Mac本软件安装之后打不开的解决办法 MacOS系统版本10.15.3 一,安装Axure RP 9 问题:安装之后打不开 提示“Axure RP 9已损坏,无法打开”或“打不开 Axure RP 9 ...

  7. 蒲公英 · JELLY技术周刊 Vol.19 从零开始的 Cloud IDE 开发

    蒲公英 · JELLY技术周刊 Vol.19 你是否也会有想法去开发一个自己的 IDE 却苦于时间和精力不足,完成 Desktop IDE 却又被 Cloud IDE 的概念追在身后难以入睡,这样的两 ...

  8. python+opencv 打开网络摄像头

    python+opencv 打开网络摄像头(手机)(转) #以下是最常用的读取视频流的方法import cv2url = 'rtsp://admin:admin@192.169.5.2:554/'#根 ...

  9. Number(),parseInt()和parseFloat

    一.Number() 1.如果是传进去数字值,只进行传入和传出,前置为  0x  的数字 和 前置  为0且不包含数字8,9的数字  ,会被转为十进制,对于其他的数字来说通常没有变化. 2.如果传进去 ...

  10. 一文教你读懂JVM类加载机制

    Java运行程序又被称为WORA(Write Once Run Anywhere,在任何地方运行只需写入一次),意味着我们程序员小哥哥可以在任何一个系统上开发Java程序,但是却可以在所有系统上畅通运 ...