nginx 本地配置(解决跨域问题)
前端做跨域本身就是扯淡的事情。后台人员不配合说什么都是白搭。索性整理了一下心得,(可以直接部署自配置)发不多说上代码:
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 本地配置(解决跨域问题)的更多相关文章
- 前端通过Nginx反向代理解决跨域问题
在前面写的一篇文章SpringMVC 跨域,我们探讨了什么是跨域问题以及SpringMVC怎么解决跨域问题,解决方式主要有如下三种方式: JSONP CORS WebSocket 可是这几种方式都是基 ...
- nginx反向代理解决跨域问题
跨域:浏览器从一个域名的网页去请求另一个域名的资源时,域名.端口.协议任一不同,都是跨域 . 下表格为前后端分离的域名,技术信息: 域名 服务器 使用技术 前端 http://b.yynf.com ...
- Nginx 反向代理解决跨域问题分析
当你遇到跨域问题,不要立刻就选择复制去尝试.请详细看完这篇文章再处理 .我相信它能帮到你. 分析前准备: 前端网站地址:http://localhost:8080 服务端网址:http://local ...
- vue webpack配置解决跨域问题
现在基本项目都是实行前后端分离的原则,不管是ng 或者是vue 在开发中都无法避免跨域的这个问题 本人刚上手第一个vue项目,在调用api的时候出现了跨域的这个问题 这是封装好一个简单的post 请求 ...
- vue项目开发,用webpack配置解决跨域问题
今天在本地开发时候碰到了跨域的问题,突然觉着跨域问题在所难免啊,之前没有没有碰到总觉着解决跨域很高大上的样纸,其实就是受限于网络的同源策略,跨域前后端都可以进行处理. 1,后端更改header hea ...
- nginx反向代理解决跨域问题,使本地调试更方便
我们可能都会遇到一个这样的问题,线上环境是https://...,本地启动了项目,域名是localhost:8000等,本地想要访问线上的接口,直接在本地调试,却提示跨域,这个时候我们可以配置ngin ...
- Nginx转发地址解决跨域问题
什么是跨域问题 在一个服务器A里放置了json文件,另一个服务器B想向A发送ajax请求,获取此文件,会发生错误. Chrome提示: XMLHttpRequest cannot load ***** ...
- 利用nginx 反向代理解决跨域问题
说到nginx,不得不说真的很强大,也带来很多便利用于解决一些头疼的难题. 一般来说可以用来做:静态页面的服务器.静态文件缓存服务器.网站反向代理.负载均衡服务器等等,而且实现这一切,基本只需要改改那 ...
- nginx反向代理解决跨域
nginx作为反向代理服务器,就是把http请求转发到另一个或者一些服务器上.通过把本地一个url前缀映射到要跨域访问的web服务器上,就可以实现跨域访问.对于浏览器来说,访问的就是同源服务器上的一个 ...
- vue前后分离项目部署(不同端口号,nginx反向代理解决跨域问题)
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #erro ...
随机推荐
- how to copy to clipboard using windows cmd
how to copy to clipboard using windows cmd Windows clipboard command line https://www.labnol.org/sof ...
- Node.js & BFF & FaaS
Node.js & BFF & FaaS server https://github.com/PacktPublishing/Node.js-Web-Development-Fourt ...
- 使用控制台启动Android设备模拟器
文档 > emulator -list-avds Nexus_5X_API_28_x86 Pixel_2_XL_API_28 > emulator.exe -avd Pixel_2_XL_ ...
- Baccarat凭什么能成为DeFi后时代火爆新趋势?
在各币种经历涨涨跌跌以后,DeFi后时代已然来临.那么,当前DeFi市场中哪个项目更被市场生态建设者看好呢?毫无疑问,Baccarat会成为最被看好的DeFi项目. Baccarat采用了独特的共识算 ...
- 为什么ElasticSearch比MySQL更适合全文索引
熟悉 MySQL 的同学一定都知道,MySQL 对于复杂条件查询的支持并不好.MySQL 最多使用一个条件涉及的索引来过滤,然后剩余的条件只能在遍历行过程中进行内存过滤,对这个过程不了解的同学可以先行 ...
- Java基础语法:数组
一.简介 描述: 数组是相同类型数据的有序集合. 其中,每一个数据称作一个数组元素,每个数组元素可以通过一个下标来访问它们. 基本特点: 数组的长度是确定的.数组一旦被创建,它的大小就是不可以改变的. ...
- 分分钟钟学会Python - 第四章 文件操作
4.1 文件基本操作 obj = open('路径',mode='模式',encoding='编码') obj.write() # 写入 obj.read() # 读取 obj.close() #关闭 ...
- Hexo一键部署到阿里云OSS并设置浏览器缓存
自建博客地址:https://bytelife.net,欢迎访问! 本文为博客自动同步文章,为了更好的阅读体验,建议您移步至我的博客 本文作者: Jeffrey 本文链接: https://bytel ...
- CTS camera的基础操作和debug
手机端 设置永久不锁屏 1 CTS 进入cts目录tools 运行以下命令 ./cts-tradefed adb devices找设备数串 整跑 run cts -m CtsCameraTestCas ...
- React开发入门:以开发Todo List为例
目录 概述 React基本概念 JSX是什么? 设置React APP 初始化APP 应用结构 探索第一个React组件 index.js 变量和props JSX中的变量 组件props props ...