ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

nginx 本地配置(解决跨域问题)

2021-04-09 17:04:30  阅读:155  来源: 互联网

标签:set log header nginx host proxy 本地 error 跨域


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

  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

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

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

标签:set,log,header,nginx,host,proxy,本地,error,跨域
来源: https://www.cnblogs.com/opcec/p/14637456.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有