CentOS 設定v2ray - 伺服器篇
v2ray係乜?
v2ray 係一個類似Shadowsocks 嘅物體,同樣可以僞裝成爲HTTP嘅Traffic,但好處就係可以support TLS。用嚟做乜?你懂的,不過我自己就用CTM嘅,喺珠海照收澳門訊號。
先決條件
Linux 嘅VPS一個
Domain Name 一個
(最好有Linux 電腦)
安裝步驟
通過 SSH 連線去個VPS
ssh [email protected]
或者
ssh [email protected] su
2. 通過script 安裝最新穩定版v2ray
bash <(curl -L -s https://install.direct/go.sh)
完成之後應該係顯示類似嘅野
麻煩記低Port 號碼,陣間有用
3. 安裝Nginx
(CentOS yum 個repo nginx 好舊,所以自己wget 落嚟,Arch Linux 可以自己pacman -S nginx / nginx-mainline,有咩param 需要config 請自行加入)
cd ~/ wget http://nginx.org/download/nginx-1.13.6.tar.gz tar zxvf nginx-1.13.6.tar.gz cd nginx-1.13.6 ./configure {param} make && make install
4. Setup nginx
cd /etc/nginx mkdir sites-enabled nano nginx.conf
然後喺http { ... } 入面輸入
include sites-enabled/*;
按 ^X 離開
5. 設定Nginx server block
cd sites-enabled nano v2ray
server { listen 80; server_name {example.com}; root {path}; } #server { #listen 443 http2; #server_name {example.com}; #index index.html index.php index.htm; #root {path}; #disable_symlinks off; #server_tokens off; #ssl on; #ssl_certificate {path}; #ssl_certificate_key {path}; #location /enterv2ray/ { #proxy_redirect off; #proxy_pass http://127.0.0.1:port; #proxy_http_version 1.1; #proxy_set_header Upgrade $http_upgrade; #proxy_set_header Connection "upgrade"; #proxy_set_header Host $http_host; #} #}
^X 離開
A 做法
6a. 如果用到certbot 就裝
arch 安裝可以參考翻 https://wiki.archlinux.org/index.php/Let%E2%80%99s_Encrypt
CentOS 未試過
然後申請ssl
certbot certonly --email [email protected] --webroot -w /var/www/ -d example.com
7a. Setup 埋Cronjob 嚟renew
sudo crontab -e (arch linux)
00 00 * * * certbot renew
8a. 最後Config
跟呢個Format
ssl_certificate /etc/letsencrypt/live/domain.tld/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/domain.tld/privkey.pem; ssl_trusted_certificate /etc/letsencrypt/live/domain.tld/chain.pem;
將堆pem入落nginx config,然後uncomment (from Arch Wiki)
B 做法
6b. 申請ssl certificate (free)
上 https://sslforfree.com/ 申請ssl cert (簽Let's Encrypt 嘅網站)
7b. 驗證domian
用DNS驗證無需Upload 任何證明文件(好似係) :0)
8b. Config
將所有Files Upload 去一個Folder
然後就將ssl on; 下面兩行嘅Path 改成ssl cert 嘅位置
^X 離開
9. 重新啓動nginx
nginx -s reload
開始設定 v2ray
10. 備份原本嘅Configuration 檔案
cp /etc/v2ray/config.json /etc/v2ray/config.json.1
11. Check 設定檔
cat /etc/v2ray/config.json
在此仍可以找到Port同埋UUID
12. 更改設定檔
rm etc/v2ray/config.json
去 https://htfy96.github.io/v2ray-config-gen/ gen一個config 出嚟,Cover 原本嗰個嘅UUID
wget https://raw.githubusercontent.com/chrischan514/v2ray-opt/master/config.json nano /etc/v2ray/config.json
13. 重新啓動v2ray
service v2ray restart
systemctl restart v2ray
(systemd-based 系統)
13a. CentOS 6.x 需要手動更改啓動嘅Script
mv /etc/init.d/v2ray /etc/init.d/v2ray.1 wget https://raw.githubusercontent.com/chrischan514/v2ray-opt/master/v2ray mv v2ray /etc/init.d/v2ray chmod +x /etc/init.d/v2ray service v2ray restart
14. 開Port
# iptables -A INPUT -p tcp --dport 22,80,443 -j ACCEPT
15. 微調設定
先Backup 原本嘅Config
cp /etc/sysctl.conf /etc/sysctl.conf.bak
再下載覆蓋(檔案作者:Michiel Klaver)
wget https://raw.githubusercontent.com/chrischan514/v2ray-opt/master/sysctl.conf mv sysctl.conf /etc/sysctl.conf
16. 重新啓動 sysctl
sysctl -p
伺服器設定完成