全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

CeraNetworks网络延迟测速工具IP归属甄别会员请立即修改密码
查看: 1657|回复: 7

[疑问] [原创] 让Trojan和 LNMP/oneinstack共存的方法

[复制链接]
发表于 2020-2-27 11:18:35 | 显示全部楼层 |阅读模式
本帖最后由 nic2013 于 2020-2-27 11:27 编辑

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

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

修改 vhost 默认配置文件。

  1. server
  2.         {
  3.         listen 80;
  4.         server_name 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. }
复制代码


发表于 2020-2-27 11:24:30 来自手机 | 显示全部楼层
监听别的端口和ss有啥区别??非443的ssl看起来就不靠谱
发表于 2020-2-27 11:19:48 | 显示全部楼层
大佬 !!起来顶
 楼主| 发表于 2020-2-27 11:28:03 | 显示全部楼层
hehekotete 发表于 2020-2-27 11:24
监听别的端口和ss有啥区别??非443的ssl看起来就不靠谱

说的也对。
发表于 2020-2-27 11:59:35 来自手机 | 显示全部楼层
应该用nginx再做一次反代,让Trojan走443出去
发表于 2020-2-27 13:16:08 | 显示全部楼层
都有nginx了,路径反代v2 ws分流不好吗,折腾的不用443端口了,trojan的伪装优势也没有了
发表于 2020-2-27 13:20:24 | 显示全部楼层
SFA 发表于 2020-2-27 11:59
应该用nginx再做一次反代,让Trojan走443出去

trojan不是普通的HTTPS,反代不了
发表于 2020-2-27 13:22:36 | 显示全部楼层
用V2不好吗?非得去折腾?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2024-4-16 12:51 , Processed in 0.083173 second(s), 10 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表