让Trojan和LNMP/OneinStack共存的详细教程:让Trojan监听非443端口

搬瓦工机场JMS

核心内容:让 Trojan监听非443端口。

新建一个 vhost 让 LNMP/OneinStack 自动申请好 Let's Encrypt 证书。

修改 vhost 默认配置文件。

  1. server

  2.         {

  3.         listen 80;

  4.         server_name http://www.hostloc.com hostloc.com;

  5.     root /data/wwwroot/default;

  6.     index index.html index.htm index.php;

  7. }




在 /usr/local/Nginx/conf/nginx.conf  的 http 字段添加如下代码

  1.     log_format  main  '$remote_addr – $remote_user [$time_local] "$request" '

  2.                       '$status $body_bytes_sent "$http_referer" '

  3.                       '"$http_user_agent" "$http_x_forwarded_for"';



/usr/local/nginx/sbin/nginx -t 测试一下,无误后 service nginx restart

让 Trojan监听非443端口,比如监听90端口。

cd /usr/src 目录,下载 Trojan 服务端 https://github.com/trojan-高墙/trojan/releases/download/v1.14.1/trojan-1.14.1-linux-amd64.tar.xz

解压 tar xf trojan-1.14.1-linux-amd64.tar.xz

在 /usr/src/trojan 目录新建一个 server.conf 配置文件

  1. {

  2.     "run_type": "server",

  3.     "local_addr": "0.0.0.0",

  4.     "local_port": 90,

  5.     "remote_addr": "127.0.0.1",

  6.     "remote_port": 80,

  7.     "password": [

  8.         "password1"

  9.     ],

  10.     "log_level": 1,

  11.     "ssl": {

  12.         "cert": "/usr/local/nginx/conf/ssl/证书实际路径.crt",

  13.         "key": "/usr/local/nginx/conf/ssl/证书实际路径.key",

  14.         "key_password": "",

  15.         "cipher_tls13":"TLS_AES_128_GCM_SHA256:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_256_GCM_SHA384",

  16. "prefer_server_cipher": true,

  17.         "alpn": [

  18.             "http/1.1"

  19.         ],

  20.         "reuse_sessiON": true,

  21.         "session_ticket": false,

  22.         "session_timeout": 600,

  23.         "plain_http_response": "",

  24.         "curves": "",

  25.         "dhparam": ""

  26.     },

  27.     "tcp": {

  28.         "no_delay": true,

  29.         "keep_alive": true,

  30.         "fast_open": false,

  31.         "fast_open_qlen": 20

  32.     },

  33.     "mysql": {

  34.         "enabled": false,

  35.         "server_addr": "127.0.0.1",

  36.         "server_port": 3306,

  37.         "database": "trojan",

  38.         "username": "trojan",

  39.         "password": ""

  40.     }

  41. }




创建 Trojan 自启服务

Debian9 系统找到/lib/systemd/system/目录,并创建trojan.service文件

CentOS7 系统找到/usr/lib/systemd/system/目录,并创建trojan.service文件

打开trojan.service文件,并写入以下代码

  1. [Unit]  

  2. Description=trojan  

  3. After=network.target  

  4.    

  5. [Service]  

  6. Type=simple  

  7. PIDFile=/usr/src/trojan/trojan/trojan.pid

  8. ExecStart=/usr/src/trojan/trojan -c "/usr/src/trojan/server.conf"  

  9. ExecReload=  

  10. ExecStop=/usr/src/trojan/trojan  

  11. PrivateTmp=true  

  12.    

  13. [Install]  

  14. WantedBy=multi-user.target



设置启动 Trojan 服务

systemctl start trojan.service  #启动 Trojan

systemctl enable trojan.service  #设置 Trojan 服务开机自启

systemctl stop trojan.service  #停止 Trojan

下载 Trojan 客户端软件

https://github.com/trojan-高墙/trojan/releases/download/v1.14.1/trojan-1.14.1-win.zip


把服务器上的 fullchain.crt 证书放到  本地 Trojan 客户端文件夹,重命名为fullchain.cer。

修改 Trojan 文件夹里面的config.json文件

  1. {

  2.     "run_type": "client",

  3.     "local_addr": "127.0.0.1",

  4.     "local_port": 1080,

  5.     "remote_addr": "www.hostloc.com",

  6.     "remote_port": 90, #与vps服务端端口一致

  7.     "password": [

  8.         "password1"

  9.     ],

  10.     "log_level": 1,

  11.     "ssl": {

  12.         "verify": true,

  13.         "verify_hostname": true,

  14.         "cert": "fullchain.cer",

  15.         "cipher_tls13":"TLS_AES_128_GCM_SHA256:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_256_GCM_SHA384",

  16. "sni": "",

  17.         "alpn": [

  18.             "h2",

  19.             "http/1.1"

  20.         ],

  21.         "reuse_session": true,

  22.         "session_ticket": false,

  23.         "curves": ""

  24.     },

  25.     "tcp": {

  26.         "no_delay": true,

  27.         "keep_alive": true,

  28.         "fast_open": false,

  29.         "fast_open_qlen": 20

  30.     }

  31. }

未经允许不得转载:搬瓦工VPS_美国VPS » 让Trojan和LNMP/OneinStack共存的详细教程:让Trojan监听非443端口

赞 (0) 打赏

相关推荐

    暂无内容!

评论 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏