nginx 本地配置(解决跨域问题)
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了nginx 本地配置(解决跨域问题),小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3602字,纯文字阅读大概需要6分钟。
内容图文
前端做跨域本身就是扯淡的事情。后台人员不配合说什么都是白搭。索性整理了一下心得,(可以直接部署自配置)发不多说上代码:
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 本地配置(解决跨域问题)所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。