前端做跨域本身就是扯淡的事情。后台人员不配合说什么都是白搭。索性整理了一下心得,(可以直接部署自配置)发不多说上代码:

  1 #user  nobody;
2 worker_processes 1;
3
4 #error_log logs/error.log;
5 #error_log logs/error.log notice;
6 #error_log logs/error.log info;
7
8 #pid logs/nginx.pid;
9
10
11 events {
12 worker_connections 1024;
13 }
14
15
16 http {
17 include mime.types;
18 default_type application/octet-stream;
19
20 #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
21 # '$status $body_bytes_sent "$http_referer" '
22 # '"$http_user_agent" "$http_x_forwarded_for"';
23
24 #access_log logs/access.log main;
25
26 sendfile on;
27 #tcp_nopush on;
28
29 #keepalive_timeout 0;
30 keepalive_timeout 65;
31
32 #gzip on;
33
34 upstream ma {
35 server t.manage.xxxxx.com;//测试服地址
36 }
37
38 upstream permission {
39 server t.manage.xxxxx.com;//测试服地址
40 }
41 54
55 server {
56 listen 80;
57 server_name t.test.cn; //此处是改变本地的host的配置(好处就是可以把这个配置文件直接部署到线上直接使用,改个名字就行),同时也是本地访问的域名
58
59 #charset koi8-r;
60
61 #access_log logs/host.access.log main;
62
63 location /permission/{
64 proxy_pass http://permission;
65 proxy_pass_header Server;
66 proxy_set_header Host t.manage.xxx.com;//这是解决服务端地址冲突的问题
67 proxy_set_header X-Real-IP $remote_addr;
68 proxy_set_header X-Scheme $scheme;
69 proxy_connect_timeout 60s;
70 client_max_body_size 30m;
71 }
72
73 location /ma/{
74 proxy_pass http://ma;
75 proxy_pass_header Server;
76 proxy_set_header Host t.manage.xxxx.com;//同上
77 # proxy_set_header Host $http_host;
78 proxy_set_header X-Real-IP $remote_addr;
79 proxy_set_header X-Scheme $scheme;
80 proxy_connect_timeout 60s;
81 client_max_body_size 30m;
82 }
83
84 location / {
85 root E:/gsthj/manage-web;//地址指向要更改
86 index login.html;
87 }
88 }
89
90 141
142
143 #error_page 404 /404.html;
144
145 # redirect server error pages to the static page /50x.html
146 #
147 error_page 500 502 503 504 /50x.html;
148 location = /50x.html {
149 root html;
150 }
151
152 }
153
154
155 }

本地host

 1 # Copyright (c) 1993-2009 Microsoft Corp.
2 #
3 # This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
4 #
5 # This file contains the mappings of IP addresses to host names. Each
6 # entry should be kept on an individual line. The IP address should
7 # be placed in the first column followed by the corresponding host name.
8 # The IP address and the host name should be separated by at least one
9 # space.
10 #
11 # Additionally, comments (such as these) may be inserted on individual
12 # lines or following the machine name denoted by a '#' symbol.
13 #
14 # For example:
15 #
16 # 102.54.94.97 rhino.acme.com # source server
17 # 38.25.63.10 x.acme.com # x client host
18
19 # localhost name resolution is handled within DNS itself.
20 # 127.0.0.1 localhost
21 # ::1 localhost
22
23 127.0.0.1 t.test.cn
24 127.0.0.1 t1.test.cn

基本的部署就是很简单的方式,更灵活的用法就要靠各位大佬自己了。

完结撒花****************************

nginx 本地配置(解决跨域问题)的更多相关文章

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

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

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

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

  3. Nginx 反向代理解决跨域问题分析

    当你遇到跨域问题,不要立刻就选择复制去尝试.请详细看完这篇文章再处理 .我相信它能帮到你. 分析前准备: 前端网站地址:http://localhost:8080 服务端网址:http://local ...

  4. vue webpack配置解决跨域问题

    现在基本项目都是实行前后端分离的原则,不管是ng 或者是vue 在开发中都无法避免跨域的这个问题 本人刚上手第一个vue项目,在调用api的时候出现了跨域的这个问题 这是封装好一个简单的post 请求 ...

  5. vue项目开发,用webpack配置解决跨域问题

    今天在本地开发时候碰到了跨域的问题,突然觉着跨域问题在所难免啊,之前没有没有碰到总觉着解决跨域很高大上的样纸,其实就是受限于网络的同源策略,跨域前后端都可以进行处理. 1,后端更改header hea ...

  6. nginx反向代理解决跨域问题,使本地调试更方便

    我们可能都会遇到一个这样的问题,线上环境是https://...,本地启动了项目,域名是localhost:8000等,本地想要访问线上的接口,直接在本地调试,却提示跨域,这个时候我们可以配置ngin ...

  7. Nginx转发地址解决跨域问题

    什么是跨域问题 在一个服务器A里放置了json文件,另一个服务器B想向A发送ajax请求,获取此文件,会发生错误. Chrome提示: XMLHttpRequest cannot load ***** ...

  8. 利用nginx 反向代理解决跨域问题

    说到nginx,不得不说真的很强大,也带来很多便利用于解决一些头疼的难题. 一般来说可以用来做:静态页面的服务器.静态文件缓存服务器.网站反向代理.负载均衡服务器等等,而且实现这一切,基本只需要改改那 ...

  9. nginx反向代理解决跨域

    nginx作为反向代理服务器,就是把http请求转发到另一个或者一些服务器上.通过把本地一个url前缀映射到要跨域访问的web服务器上,就可以实现跨域访问.对于浏览器来说,访问的就是同源服务器上的一个 ...

  10. vue前后分离项目部署(不同端口号,nginx反向代理解决跨域问题)

    #user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #erro ...

随机推荐

  1. How to get a DOM element's ::before content with JavaScript?

    How to get a DOM element's ::before content with JavaScript? https://stackoverflow.com/questions/443 ...

  2. gradient text & gradient background

    gradient text & gradient background -webkit-text-fill-color & -webkit-gradient https://wesbo ...

  3. svg 矩阵转换

    svg 矩阵转换 https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix https://develope ...

  4. PAUL ADAMS ARCHITECT:澳洲房贷最低利率来袭

    11月3日澳洲储备银行宣布将官方现金利率从0.25%降至0.1%,破历史最低纪录.此次澳洲储备银行降息的目的主要是为了刺激经济走出全球经济危机引发的衰退.据了解,这已经是澳洲今年第三次降息,也是自20 ...

  5. C++算法代码——骨牌铺法

    题目来自:http://218.5.5.242:9018/JudgeOnline/problem.php?id=1638 题目描述 输入 输入一个正整数,表示n. 输出 输出一个正整数,表示铺法. 样 ...

  6. react小白笔记

    diff算法主要是同级比较,生成数组,进行数组替换 reducer可以接收state,但是绝不能修改state 纯函数指的是:给固定收入,就一定有固定的输出,而且不会有任何副作用[不能例如:new d ...

  7. Django Admin 在内联中覆盖保存方法(admin.TabularInline)

    一  使用环境 开发系统: windows IDE: pycharm 数据库: msyql,navicat 编程语言: python3.7  (Windows x86-64 executable in ...

  8. 微信小程序:post请求参数放在请求体中还是拼接到URL中需要看后台是如何接收的

    前端发送post请求时,请求参数可以放在请求中,代码如下: function post(url, data, callback) { wx.request({ method: 'POST', url: ...

  9. MYSQL bin_log 开启及数据恢复

    参考博客: A:https://www.jianshu.com/p/55b0d52edca2 B:https://www.cnblogs.com/martinzhang/p/3454358.html ...

  10. 翻译:《实用的 Python 编程》02_07_Objects

    目录 | 上一节 (2.6 列表推导式) | 下一节 (3 从程序组织) 2.7 对象 本节介绍有关 Python 内部对象模型的更多详细信息,并讨论一些与内存管理,拷贝和类型检查有关的问题. 赋值 ...