nginx 反向代理配置

2019-05-13

服务器环境为 centos 7

配置路径Ct 反向代理服务器本地3001端口 服务为

https://github.com/jpillora/cloud-torrent

	upstream clbt {
    # server backend1.example.com weight=5;
    # server 127.0.0.1:8080       max_fails=3 fail_timeout=30s;
    # server unix:/tmp/backend3;
server 127.0.0.1:3001;
    # server backup1.example.com  backup;
}

cloud torrent 部分 Server-sent Events 

		location /ct/ {
			   # rewrite ^/*(.*) $1 break;

			proxy_pass http://127.0.0.1:3001/;
			# proxy_pass http://clbt;
				# gzip off;
			proxy_http_version	1.1;
			# proxy_cache_bypass	$http_upgrade;
# 			proxy_set_header Connection "";
# proxy_buffering off;
# proxy_cache off;
# chunked_transfer_encoding off;
# add_header Cache-Control "no-cache" always;
	# add_header Content-Type "text/event-stream" always;

	proxy_set_header X-Accel-Buffering no;
			proxy_set_header Upgrade			$http_upgrade;
			proxy_set_header Connection 		"upgrade";
			proxy_set_header Host				$host;
			proxy_set_header X-Real-IP			$remote_addr;
			proxy_set_header X-Forwarded-For	$proxy_add_x_forwarded_for;
			proxy_set_header X-Forwarded-Proto	$scheme;
			proxy_set_header X-Forwarded-Host	$host;
			proxy_set_header X-Forwarded-Port	$server_port;
		}
	location /sync {
			   # rewrite ^/*(.*) $1 break;
# add_header Content-Type text/plain;
			# proxy_pass http://127.0.0.1:3001/;
			proxy_pass http://clbt$request_uri;
			# proxy_pass clbt;
			gzip off;
			proxy_http_version	1.1;
			# proxy_cache_bypass	$http_upgrade;
			proxy_set_header Connection "";
proxy_buffering off;
proxy_cache off;
chunked_transfer_encoding off;
add_header Cache-Control "no-cache" always;
	add_header Content-Type "text/event-stream" always;

	proxy_set_header X-Accel-Buffering no;
			proxy_set_header Upgrade			$http_upgrade;
			proxy_set_header Connection 		"upgrade";
			proxy_set_header Host				$host;
			proxy_set_header X-Real-IP			$remote_addr;
			proxy_set_header X-Forwarded-For	$proxy_add_x_forwarded_for;
			proxy_set_header X-Forwarded-Proto	$scheme;
			proxy_set_header X-Forwarded-Host	$host;
			proxy_set_header X-Forwarded-Port	$server_port;
		}
 sudo nginx -s reload