 
            八合一脚本配置反向代理到其他服务
RackNerd 联通AS4837、移动CMI深度评测【推荐观看】
Telegram频道、Telegram群,欢迎加入频道、群组交流
有很多人询问安装八合一之后是否可以反向代理自己的服务。答案是可以的。
使用脚本正常安装后,会有两种配置方式。
第一种是依赖于xray-core 回落(此方法仅支持xray-core的核心)。
另一种是依赖于nginx(此方法支持xray-core和sing-box)。注意端口不可以和其他服务重复。
一、xray-core回落
1.介绍
- 此方法不占用新的端口,使用xray-core的端口,依赖于xray-core回落。 
- 仅支持使用TLS证书的协议。 
2.配置示例
第一步打开配置文件 /etc/nginx/conf.d/alone.conf,找到 location / { 这行,能找到两个这样的代码块,端口分别监听的是31302和31300。
如果只找到一个则只需要修改一个。在他的代码块后面增加反向代理的代码。
- 修改的代码块示例 
# 修改的代码块示例
location / {
	# 下面是添加的内容
	proxy_pass http://127.0.0.1:3302; # 这里的端口是真实端口
}- 完整的配置示例 
# 完整配置示例
# 下面的example.com对应的是自己实际使用的域名
server {
    listen 127.0.0.1:31300;
    server_name _;
    return 403;
}
server {
    listen 127.0.0.1:31302 http2 so_keepalive=on proxy_protocol;
    set_real_ip_from 0.0.0.0/0;
    real_ip_header proxy_protocol;
    server_name example.com;# 替换example为实际使用的域名
    root /usr/share/nginx/html/;
    location ~ ^/s/(clashMeta|default|clashMetaProfiles|sing-box|sing-box_profiles)/(.*) {
        proxy_set_header X-Real-IP $proxy_protocol_addr;
        default_type 'text/plain; charset=utf-8';
        alias /etc/v2ray-agent/subscribe/$1/$2;
    }
    location / {
		# 这里是增加的代码
        proxy_pass http://127.0.0.1:3302; # 替换3302为真实的服务端口
    }
}
server {
    listen 127.0.0.1:31300 proxy_protocol;
    server_name example.com;# 替换example为实际使用的域名
    set_real_ip_from 0.0.0.0/0;
    real_ip_header proxy_protocol;
    root /usr/share/nginx/html/;
    location ~ ^/s/(clashMeta|default|clashMetaProfiles|sing-box|sing-box_profiles)/(.*) {
        proxy_set_header X-Real-IP $proxy_protocol_addr;
        default_type 'text/plain; charset=utf-8';
        alias /etc/v2ray-agent/subscribe/$1/$2;
    }
    location / {
        # 这里是增加的代码
        proxy_pass http://127.0.0.1:3302;# 替换3302为真实的服务端口
	}	
}3.重启nginx
nginx -s reload二、Nginx
1.介绍
- 使用nginx进行配置,需要手动写配置。 
- 如果使用https则需要脚本安装使用证书的协议。 
2.配置示例
第一步,创建nginx配置文件
touch /etc/nginx/conf.d/server.conf第二步,将下面的配置写入到上方创建的文件中,下面有http配置和https配置请结合自己的需求进行书写。
- HTTP配置 
server {
    listen port; # 需要将 port 替换成真实的端口
    server_name example; # 替换example为实际使用的域名
    root /usr/share/nginx/; # 如果要配置静态目录,则修改root后面的路径
    location / {
	}
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
	}
}
- HTTPS配置 
server {
    listen port http2 ssl; # 需要将 port 替换成真实的端口
    server_name example; # 替换example为实际使用的域名
	ssl_certificate_key /etc/v2ray-agent/tls/example.key; # 替换example为实际使用的域名
	ssl_certificate /etc/v2ray-agent/tls/example.crt; # 替换example为实际使用的域名
    root /usr/share/nginx/; # 如果要配置静态目录,则修改root后面的路径
    location / {
        proxy_pass http://127.0.0.1:3302;# 替换3302为真实的服务端口
	}
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
	}
}3.重启nginx
nginx -s reload 评论
            
                匿名评论
                隐私政策
            
            
                你无需删除空行,直接评论以获取最佳展示效果
            
        