安装docker版Xray并开启tls功能

一、部署docker环境

对于centos 7来说,输入以下安装命令

yum install -y docker

安装完成后,接着下一步。如果安装出错,把系统升级以下

yum update

二、准备Xray

1.拉取镜像

docker pull teddysun/xray

2.申请免费的https证书,一年免费

3.创建xray文件夹和安装nginx

mkdir -p /etc/xray

mkdir -p /etc/xray/ssl

安装nginx

yum install -y nginx

service nginx start

chkconfig nginx on

3.创建config.json配置文件

vi /etc/xray/config.json


{
    "log": {
        "loglevel": "info"
    },
    "inbounds": [
        {
            "port": 443,
            "protocol": "vless",
            "settings": {
                "clients": [
                    {
                        "id": "f9950445-a796-454d-a2c7-9745dc2eb9e3",
                        "flow": "xtls-rprx-direct",
                        "level": 0
                    }
                ],
                "decryption": "none",
                "fallbacks": [
                    {
                        "dest": "127.0.0.1:80"
                    }
                ]
            },
            "streamSettings": {
                "network": "tcp",
                "security": "xtls",
                "xtlsSettings": {
                    "alpn": [
                        "http/1.1"
                    ],
                    "certificates": [
                        {
                            "certificateFile": "/etc/xray/ssl/chain.crt",
                            "keyFile": "/etc/xray/ssl/key.key"
                        }
                    ]
                }
            }
        }
    ],
    "outbounds": [
        {
            "protocol": "freedom"
        }
    ]
}

5.启动容器

docker run -d -p 443:443 --name xray --restart=always -v /etc/xray:/etc/xray teddysun/xray