为V2ray + nginx指定IP地址

为V2ray + nginx指定IP地址

有一台配置了 nginx 和带有 x-ui 的 trojan 代理的 Ubuntu 服务器。nginx 监听公共 IP 地址端口 443,x-ui 监听 127.0.0.1,并且可以监听任何端口。trojan 代理也监听 127.0.0.1,它们在域上使用路径变量,因此 nginx 可以将相关包转发到 127.0.0.1 上的特定端口

每个客户端代理都连接443端口,nginx会把v2ray的数据包转发到127.0.0.1和v2ray代理监听的端口,这是我的配置文件。

server {
        root /var/www/html;

        index index.html index.htm index.nginx-debian.html;

        server_name myDomain.org;
        
        location /2hehwk3h {
                proxy_pass http://127.0.0.1:5473;
        }

        # This is where nginx forwards trojan proxy packets to 127.0.0.1
        location ~ ^/style/item/([0-9]+)$ {
                proxy_redirect off;
                proxy_pass http://127.0.0.1:$1;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
                proxy_set_header Host $http_host;
                # V2Ray Panel Logs
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

        #listen 443 http2 ssl;
        listen 443;
        listen 80;
        ssl_certificate /root/myDomain.org.crt;
        ssl_certificate_key /root/myDomain.org.key;
}

我的服务器有一个 ipv4 ip 地址和四个 ipv6 地址。当我连接到代理并在 google 上搜索我的 IP 地址时,一些网站显示我的 ipv4 地址和其他一些 ipv6 地址。

有没有办法指定哪个 IP 应该用于哪个代理配置文件?

由于每个配置文件都使用本地主机上的特定端口,所以我想我可以在 nginx 配置文件上执行类似的操作:

# I think I can add this block and specify the IP address (ipv4) here so every packets on the profile that configured on port 53243 will use ipv4. 
location ~ ^/style/item/53243 {
                proxy_redirect off;
                proxy_pass http://127.0.0.1:$1;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
                proxy_set_header Host $http_host;
                # V2Ray Panel Logs
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

# This is the configuration I have, I just have to set an IP address to be used as default here: 
location ~ ^/style/item/([0-9]+)$ {
                proxy_redirect off;
                proxy_pass http://127.0.0.1:$1;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
                proxy_set_header Host $http_host;
                # V2Ray Panel Logs
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

但我不确定。

有吗?

相关内容