全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

IP归属甄别会员请立即修改密码
楼主: 坏坏
打印 上一主题 下一主题

xray配置谁能给一份,主要是nginx的回落,搞不定啊

[复制链接]
21#
发表于 2023-2-17 12:32:23 | 只看该作者
"security": "tls"
然后客户端用xtls
22#
发表于 2023-2-17 12:38:59 | 只看该作者
nginx前置分流, xray后置的。
这是xray的配置
  1. {
  2.     "log": {
  3.         "loglevel": "warning",
  4.         "access": "/var/log/xray/access.log",
  5.         "error": "/var/log/xray/error.log"
  6.     },
  7.     "dns": {
  8.         "servers": [
  9.             "https+local://8.8.8.8/dns-query"
  10.         ]
  11.     },
  12.     "routing": {
  13.         "domainStrategy": "IPIfNonMatch",
  14.         "domainMatcher": "mph",
  15.         "rules": [
  16.             // rules 自己配置
  17.         ]
  18.     },
  19.     "inbounds": [
  20.         {
  21.             "listen": "127.0.0.1",
  22.             "port": 41256, // 端口自己定义, 跟 nginx 配置中留存的端口一致
  23.             "protocol": "vless",
  24.             "settings": {
  25.                 "clients": [
  26.                     {
  27.                         "id": "xxxxxxxxxxxxx",
  28.                         "level": 0,
  29.                         "email": "",
  30.                         "flow": "xtls-rprx-vision"
  31.                     }
  32.                 ],
  33.                 "decryption": "none"
  34.             },
  35.             "sniffing": {
  36.                 "enabled": true,
  37.                 "destOverride": [
  38.                     "http",
  39.                     "tls"
  40.                 ]
  41.             },
  42.             "streamSettings": {
  43.                 "network": "tcp",
  44.                 "security": "tls",
  45.                 "tlsSettings": {
  46.                     "rejectUnknownSni": true,
  47.                     "certificates": [
  48.                         {
  49.                             "ocspStapling": 3600,
  50.                             "oneTimeLoading": false,
  51.                             "usage": "encipherment",
  52.                             "certificateFile": "/usr/ssl/chain.pem",         // 证书地址
  53.                             "keyFile": "/usr/ssl/key.pem"                // key地址
  54.                         }
  55.                     ]
  56.                 },
  57.                 "tcpSettings":{
  58.                     "acceptProxyProtocol": true,
  59.                     "header": {
  60.                         "type": "none"
  61.                       }
  62.                 }
  63.             }
  64.         }
  65.     ],
  66.     "outbounds": [
  67.         {
  68.             "protocol": "freedom",
  69.             "tag": "direct",
  70.             "settings": {
  71.                 "domainStrategy": "UseIP"
  72.             }
  73.         },
  74.         {
  75.             "protocol": "blackhole",
  76.             "tag": "block",
  77.             "settings": {
  78.                 "response": {
  79.                     "type": "http"
  80.                 }
  81.             }
  82.         }
  83.     ]
  84. }
复制代码


这是nginx的配置
  1. user www-data;
  2. worker_processes auto;
  3. pid /run/nginx.pid;
  4. include /etc/nginx/modules-enabled/*.conf;

  5. events {
  6.     worker_connections 768;
  7.     # multi_accept on;
  8. }

  9. # tcp 四层分流
  10. stream {

  11.     log_format log_stream '$remote_addr [$time_local] $protocol '
  12.         '[$ssl_preread_server_name] [$ssl_preread_alpn_protocols] '
  13.         '$status $bytes_sent $bytes_received $session_time';

  14.     error_log   /var/log/nginx/pserver/error.log info;                // 注意,请创建 /var/log/nginx/pserver/文件夹
  15.     access_log  /var/log/nginx/pserver/access.log log_stream;

  16.     map $ssl_preread_server_name $stream_map {
  17.         # 服务站点
  18.         default homepage;                                // 除 xray 域名,其他的域名分流到 homepage
  19.         # 伪装代理
  20.         xray.example.com xray_core;                // xray.example.com : xray对应的域名,分流到 xray_core
  21.     }
  22.     # 服务站点
  23.     upstream homepage {
  24.         server 127.0.0.1:41255;                        // 41255端口, nginx 网页监听 端口
  25.     }
  26.     # 伪装代理
  27.     upstream xray_core {
  28.         server 127.0.0.1:41256;                           // 41256端口, 前面 xray 监听的端口
  29.     }                                                                                                         
  30.     server {
  31.         listen 443;
  32.         proxy_pass $stream_map;
  33.         proxy_protocol on;
  34.         ssl_preread on;
  35.     }
  36. }

  37. http {

  38.     ##
  39.     # Basic Settings
  40.     ##

  41.     sendfile on;
  42.     tcp_nopush on;
  43.     types_hash_max_size 2048;
  44.     # server_tokens off;

  45.     # server_names_hash_bucket_size 64;
  46.     # server_name_in_redirect off;

  47.     include /etc/nginx/mime.types;
  48.     default_type application/octet-stream;

  49.     ##
  50.     # Logging Settings
  51.     ##
  52.                      
  53.     log_format  main  '$proxy_protocol_addr - $remote_user [$time_local] "$request" '
  54.                       '$status $body_bytes_sent "$http_referer" '
  55.                       '"$http_user_agent" "$http_x_forwarded_for"';

  56.     access_log /var/log/nginx/access.log main;
  57.     error_log /var/log/nginx/error.log;

  58.     ##
  59.     # SSL Settings
  60.     ##
  61.     ssl_certificate /usr/ssl/chain.pem;     // ssl证书地址
  62.     ssl_certificate_key /usr/ssl/key.pem;     // ssl key 地址

  63.     ssl_session_timeout 1d;
  64.     ssl_session_cache shared:MozSSL:10m;
  65.     ssl_session_tickets off;
  66.     ssl_protocols TLSv1.3;
  67.     ssl_prefer_server_ciphers off;
  68.     add_header Strict-Transport-Security "max-age=63072000" always;

  69.     # OCSP stapling
  70.     ssl_stapling on;
  71.     ssl_stapling_verify on;

  72.     ##
  73.     # Gzip Settings
  74.     ##

  75.     gzip on;

  76.     gzip_vary on;
  77.     gzip_proxied any;
  78.     gzip_min_length 1k;
  79.     gzip_comp_level 2;
  80.     gzip_buffers 16 8k;
  81.     gzip_http_version 1.1;
  82.     gzip_disable "MSIE [1-6]\.";
  83.     gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

  84.     ##
  85.     # Virtual Host Configs
  86.     ##

  87.     include /etc/nginx/conf.d/*.conf;
  88.     include /etc/nginx/sites-enabled/*;
  89.   
  90.     # proxy_protocol协议将访问IP修改为客户端IP
  91.     set_real_ip_from 127.0.0.1;
  92.     real_ip_header proxy_protocol;

  93.     # 端口转发设置
  94.     absolute_redirect on;
  95.     port_in_redirect off;
  96.     server_name_in_redirect off;

  97.     server {
  98.         listen 80;
  99.         server_name example.com;                // 注意修改域名
  100.         return 301 https://$host$request_uri;                // 强制重定向到 https
  101.     }

  102.     server {
  103.         listen 127.0.0.1:41255 ssl http2 proxy_protocol;
  104.         server_name aaa.example.com;  // 网站域名,注意修改域名
  105.        
  106.         // 自行配置网站

  107.     }

  108.     server {  // 如果有域名分流,请这样配置。 如果没有, 可以删除
  109.         listen 127.0.0.1:41255 ssl http2 proxy_protocol;
  110.         server_name bbb.example.com;        // 分流的网站域名: bbb.example.com


  111.         // 自行配置网站        
  112.     }
  113.    
  114. }


  115. #mail {
  116. #        # See sample authentication script at:
  117. #        # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
  118. #
  119. #        # auth_http localhost/auth.php;
  120. #        # pop3_capabilities "TOP" "USER";
  121. #        # imap_capabilities "IMAP4rev1" "UIDPLUS";
  122. #
  123. #        server {
  124. #                listen     localhost:110;
  125. #                protocol   pop3;
  126. #                proxy      on;
  127. #        }
  128. #
  129. #        server {
  130. #                listen     localhost:143;
  131. #                protocol   imap;
  132. #                proxy      on;
  133. #        }
  134. #}
复制代码
23#
发表于 2023-2-17 12:41:48 | 只看该作者
omo.moe 发表于 2023-2-17 12:31
nginx本身不具备流量识别能力,以前的vmess vless是指定/path 做跳转给后置v2ray xray等处理。xtls的tls  ...

可以的。你看我在楼里发的配置。 nginx可以做前置服务器的。 在监听到443端口发来的请求后,直接根据域名进行分流,不需要用证书解密, 直接将完整的 https 请求转发。 这样是可以实现的。
24#
发表于 2023-2-17 12:43:59 | 只看该作者
time12sads 发表于 2023-2-17 12:41
可以的。你看我在楼里发的配置。 nginx可以做前置服务器的。 在监听到443端口发来的请求后,直接根据域名 ...

明白了,你是用upstream分流了二级域名转发了,也算行吧,我还一直思考怎么用同一个域名做分流来着的。
25#
发表于 2023-2-17 12:48:02 | 只看该作者
omo.moe 发表于 2023-2-17 12:43
明白了,你是用upstream分流了二级域名转发了,也算行吧,我还一直思考怎么用同一个域名做分流来着的。 ...

我一直是为 xray 单独设了一个二级域名, 毕竟之前nginx前置时,vmess + ws +tls,  也需要二级域名。
xray前置的xtls,可以共用一个域名吗?这个我之前没有试过。
26#
发表于 2023-2-17 12:50:34 | 只看该作者
time12sads 发表于 2023-2-17 12:48
我一直是为 xray 单独设了一个二级域名, 毕竟之前nginx前置时,vmess + ws +tls,  也需要二级域名。
xra ...

以前nginx前置标准vmess或者vless我都是nginx指定path路径转发后端。而现在的xray前置还是以前的v2ray vless前置,都是fallback 普通网站流量到后置监听的nginx进行处理,也就是vps里面做了个类似回环的感觉,但是外部访问443依然是正常的nginx处理结果,无感知区别的。就像楼主这种直接xray接听443,将不是vision流量发给nginx,直接同域名直接访问就是https标准nginx内容,不需要2个域名或者二级域名区分
27#
发表于 2023-2-17 12:53:32 | 只看该作者
omo.moe 发表于 2023-2-17 12:50
以前nginx前置标准vmess或者vless我都是nginx指定path路径转发后端。而现在的xray前置还是以前的v2ray vl ...

这样啊,谢谢你
28#
发表于 2023-2-17 12:55:47 | 只看该作者
time12sads 发表于 2023-2-17 12:48
我一直是为 xray 单独设了一个二级域名, 毕竟之前nginx前置时,vmess + ws +tls,  也需要二级域名。
xra ...

xray前置接手对应vision数据流,不符合标准的数据第一次fallback做一个trojan,可以作为iplc同端口中转trojan用,然后正常nginx网站流量再fallback给80的nginx:

  1. {
  2.    "log":{
  3.       "loglevel":"warning",
  4.       "access":"C:\\Software\\Xray-windows-64\\access.log",
  5.       "error":"C:\\Software\\Xray-windows-64\\error.log"
  6.    },
  7.    "routing":{
  8.       "domainStrategy":"IPIfNonMatch",
  9.       "rules":[
  10.          {
  11.             "type":"field",
  12.             "ip":[
  13.                "geoip:cn",
  14.                "geoip:private"
  15.             ],
  16.             "outboundTag":"block"
  17.          }
  18.       ]
  19.    },
  20.    "inbounds":[
  21.       {
  22.          "port":443,
  23.          "protocol":"vless",
  24.          "settings":{
  25.             "clients":[
  26.                {
  27.                   "id":"你的UUID",
  28.                   "flow":"xtls-rprx-vision"
  29.                }
  30.             ],
  31.             "decryption":"none",
  32.             "fallbacks":[
  33.                {
  34.                   "dest":12345,
  35.                   "xver":1
  36.                }
  37.             ]
  38.          },
  39.          "streamSettings":{
  40.             "network":"tcp",
  41.             "security":"tls",
  42.             "tlsSettings":{
  43.                "rejectUnknownSni":true,
  44.                "alpn":[
  45.                   "http/1.1"
  46.                ],
  47.                "certificates":[
  48.                   {
  49.                      "certificateFile":"C:\\Software\\Xray-windows-64\\web.crt",
  50.                      "keyFile":"C:\\Software\\Xray-windows-64\\web.key"
  51.                   }
  52.                ]
  53.             }
  54.          },
  55.          "sniffing":{
  56.             "enabled":true,
  57.             "destOverride":[
  58.                "http",
  59.                "tls"
  60.             ]
  61.          }
  62.       },
  63.       {
  64.          "port":12345,
  65.          "listen":"127.0.0.1",
  66.          "protocol":"trojan",
  67.          "settings":{
  68.             "clients":[
  69.                {
  70.                   "password":"password"
  71.                }
  72.             ],
  73.             "fallbacks":[
  74.                {
  75.                   "dest":80
  76.                }
  77.             ]
  78.          },
  79.          "streamSettings":{
  80.             "network":"tcp",
  81.             "security":"none",
  82.             "tcpSettings":{
  83.                "acceptProxyProtocol":true
  84.             }
  85.          }
  86.       }
  87.    ],
  88.    "outbounds":[
  89.       {
  90.          "protocol":"freedom",
  91.          "tag":"direct"
  92.       },
  93.       {
  94.          "protocol":"blackhole",
  95.          "tag":"block"
  96.       }
  97.    ]
  98. }
复制代码


nginx配置只要监听80端口即可,这样就可以443访问直接就是nginx的网站配置了,简单配置个bing反代演示:
  1. events {
  2.     worker_connections 1024;
  3. }

  4. http {

  5.   server {
  6.     listen 80 default_server;
  7.     listen [::]:80 default_server;

  8.   location / {
  9.     proxy_pass https://www.bing.com;
  10.     proxy_ssl_server_name on;
  11.     proxy_redirect off;
  12.     sub_filter_once off;
  13.     sub_filter "www.bing.com" $server_name;
  14.     proxy_set_header Host "www.bing.com";
  15.     proxy_set_header Referer $http_referer;
  16.     proxy_set_header X-Real-IP $remote_addr;
  17.     proxy_set_header User-Agent $http_user_agent;
  18.     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  19.     proxy_set_header X-Forwarded-Proto https;
  20.     proxy_set_header Accept-Encoding "";
  21.     proxy_set_header Accept-Language "zh-CN";
  22.     }
  23.   }
  24. }
复制代码
29#
发表于 2023-2-17 12:59:02 | 只看该作者

客气了,现在xray这思路就是尽量简洁,一个前置接管443可以all in one处理各种fallback后端监听,并且和nginx互不干扰,你可以看看这个all in one 配置示例,自行增删就可以了,fallback本身也可以一级级嵌套,和这演示的扁平化分流都行的:
https://github.com/XTLS/Xray-examples/tree/main/All-in-One-fallbacks-Nginx
30#
 楼主| 发表于 2023-2-17 13:36:54 | 只看该作者
omo.moe 发表于 2023-2-17 12:59
客气了,现在xray这思路就是尽量简洁,一个前置接管443可以all in one处理各种fallback后端监听,并且和n ...

nginx 作前端方便点,,,还是xray做前端分流到nginx好用点

要是我还要用nginx 分流几个网站,,,怎么配置好

我原来用的是你用的办法,nginx做前端,用路径path分流
ws + 域名 +443
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-15 01:30 , Processed in 0.068334 second(s), 9 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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