NGINX在前xray在后

于 2021-07-22 发布

参考Xray+VLESS+XTLS+NginxSNI分流/443端口复用

nginx.conf里面需要添加一个stream map:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
stream {
    map $ssl_preread_server_name $huaj_xray {
        wordpress.mutebot.net wordpress;
        cloud.mutebot.net nextcloud;
        mcsm.mutebot.net mcsm;
        mirgit.mutebot.net mirgit;
        wiki.mutebot.net wiki;
        static.mutebot.net static;
        www.mutebot.net www;
        mutebot.net www;
        config.mutebot.net servertool;
        blog.mutebot.net hugo;
    }
    upstream hugo{
        server 127.0.0.1:51010;
    }
    upstream servertool{
        server 127.0.0.1:51009;
    }
    upstream www{
        server 127.0.0.1:51000;
    }
    upstream static{
        server 127.0.0.1:51008;
    }
    upstream wordpress {
        server 127.0.0.1:51001;

    }
    upstream nextcloud {
        server 127.0.0.1:51002;
    }
    upstream mcsm {
        server 127.0.0.1:51003;
    }
    upstream mirgit {
        server 127.0.0.1:51004;
    }
    upstream wiki {
        server 127.0.0.1:51005;
    }
    server {
        listen 443 reuseport;
        proxy_pass $huaj_xray;
        ssl_preread on;
    }

    log_format proxy '$remote_addr [$time_local] '
                '$protocol $status $bytes_sent $bytes_received '
                '$session_time "$upstream_addr" '
                '"$upstream_bytes_sent" "$upstream_bytes_received" "$upstream_connect_time"';
    access_log /var/log/nginx/access.log proxy;
}

然后用来做伪装的网站的conf:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
server {
    listen 80;
    server_name mcsm.mutebot.net;
    # ACME-challenge
    include acme.conf;
    if ($host = mcsm.mutebot.net) {
                return 301 https://$host$request_uri;
        }
    return 404;
}

server {
    listen 127.0.0.1:52001;
    server_name mcsm.mutebot.net;
    index index.html;
    root /var/www/mcsm.mutebot.net;
}

config.json:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
{
    "log": {
        "loglevel": "warning"
    },
    "policy":{
        "levels": {
    "0": {
    "handshake": 15,
    "connIdle": 300,
    "uplinkOnly": 15,
    "downlinkOnly": 15,
    "statsUserUplink": false,
    "statsUserDownlink": false,
    "bufferSize": 10240
    }
}
    },

    "inbounds": [
        {
            "listen": "127.0.0.1", 
            "port": 51003,
            "protocol": "vless",
            "settings": {
                "clients": [
                    {
                        "id": "",
                        "flow": "xtls-rprx-direct"
                    }
                ],
                "decryption": "none",
                "fallbacks": [
                    {
                        "dest": "52001"
                    }
                ]
            },
            "streamSettings": {
                "network": "tcp",
                "security": "xtls",
                "xtlsSettings": {
                    "alpn": [
                        "http/1.1"
                    ],
                    "certificates": [
                        {
                            "certificateFile": "/usr/local/etc/xray/fullchain.pem",
                            "keyFile": "/usr/local/etc/xray/privkey.pem"
                        }
                    ]
                }
            }, "sniffing": {
                "enabled": true,
                "destOverride": [
                "http",
                "tls"
                ]
            }
        }
    ],
    "outbounds": [
        {
            "protocol": "freedom"
        }
    ]
}

目录