nginx 反向代理配置笔记 - Go语言中文社区

nginx 反向代理配置笔记


遇到的跨域问题,在无法靠后台人员解决的情况下,考虑使用反向代理进行了配置,如下

首先下载nginx 安装包,解压后目录显示:


conf->nginx.conf文件打开,设置 include  reverse-proxy.conf(同级目录下自定义配置文件)内容如下

	#公共js、css
	#server{
    #    listen       80;
    #    server_name  127.0.0.1;
    #    location /{
    #        root   G:\svn_home\LiveRoomForPC;
    #       index  index.html;
    #    }
    #    location /api{
    #	    rewrite  ^.+api/?(.*)$ /$1 break;
    #        include  uwsgi_params;
    #       proxy_pass   http://192.168.0.11:8018;
    #    }
    #    access_log logs/public_test.log;
    #}
	server{
        listen       8001;
        server_name  127.0.0.1;
        location /{
            root   G:\svn_home\appChart;
            index  index.html;
        }
        location /api{
    	    rewrite  ^.+api/?(.*)$ /$1 break;
            include  uwsgi_params;
            proxy_pass   http://192.168.0.11:8018;
        }
        access_log logs/public_test.log;
    }
	server{
        listen       8001;
        server_name  127.0.0.1;
        location /{
            root   G:\svn_home\appChart;
            index  index.html;
        }
        location /api{
    	    rewrite  ^.+api/?(.*)$ /$1 break;
            include  uwsgi_params;
            proxy_pass   http://192.168.0.11:8018;
        }
        access_log logs/public_test.log;
    }
	
	upstream socket_nodes {
		ip_hash;
		server 127.0.0.1:3000
	}

	# the nginx server instance
	server {
		 listen       80;
		server_name  127.0.0.1;
		access_log logs/public_test.log;

		# pass the request to the node.js server with the correct headers
		# and much more can be added, see nginx config options
		location / {
		  proxy_set_header X-Real-IP $remote_addr;
		  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		  proxy_set_header Host $http_host;
		  proxy_set_header X-NginX-Proxy true;

		  proxy_pass http://127.0.0.1/;
		  proxy_redirect off;
		}
	 }

这就是一个端口的代理配置


版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/z2181745/article/details/79732110
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2020-03-07 09:43:05
  • 阅读 ( 1138 )
  • 分类:Go Web框架

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢