nginx 反向代理配置笔记

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

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

nginx 反向代理配置笔记_第1张图片

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;
		}
	 }

nginx 反向代理配置笔记_第2张图片

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


你可能感兴趣的:(nginx)