How To Use Nginx Redirect Function To Decorate V2ray Request As Https Request

In previous article How To Install BT VPS Control Panel And Restore WordPress Website Into It i had do following things.

  1. Install BT(宝塔) VPS control panel in a Linux VPS.
  2. Install Nginx server in above Linux VPS server.
  3. Create a website in the Nginx server.
  4. Register a domain point to the website.
  5. Enable SSL for the website.
  6. Install v2ray server in the Linux VPS.
  7. Use V2RayX client to connect to the v2ray server use v2ray server port number and ip address.

In this article, i will tell you how to configure Nginx to redirect websocket ssl request to the v2ray server. Because ssl request 443 port, then this can simulate ssl request to a domain website, this is normal domain ssl request with normal port number. This kind of request do not has so many characters, so can avoid being blocked.

1. Configure Nginx To Redirect SSL Request To V2ray Server.

  1. Login to BT(宝塔) VPS control panel.
  2. Click 网站 menu in left navigation panel.
    bt panel software shop panel
  3. Then click the website domain name link in right website list panel.
    bt website list page-1
  4. Click 配置文件 menu in the popup window.
    bt configure nginx settings to redirect ssl request to v2ray server
  5. Then copy below code at the end of right Nginx settings text area. Please remember the location parameter’s value /MicroCode ( you can set it as anything that you want), it is client ssl request url path. The proxy_pass parameter’s value is the v2ray access url with port number ( use your v2ray port number to replace below example port number ).
       access_log /www/wwwlogs/health-is-easy.website.log;
       error_log /www/wwwlogs/health-is-easy.website.error.log;
    
    
    # Remember this location path, this path will be configured in v2ray client software. 
    location /MicroCode {
       proxy_redirect off;
    
       # Below is the v2ray server access url.
       proxy_pass http://127.0.0.1:18239;
       proxy_http_version 1.1;
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection "upgrade";
       proxy_set_header Host $http_host;
    }

2. Configure V2ray Server Add streamSettings Configuration Data In /etc/v2ray/config.json File.

If you are not familiar with v2ray server configuration, please read article How To Install V2ray On Amazon EC2 And Google Cloud Ubuntu Linux first.

  1. Run command sudo vim /etc/v2ray/config.json in a terminal to edit v2ray server configuration file.
  2. Ad streamSettings configuration in inbounds settings. Please see below configuration text. The “streamSettings” —> “network” value is “ws”, the “streamSettings” —> “wsSettings” —> “path” value ( /MicroCode ) is the path value that you configured in Nginx server configuration file. In vim, press esc, i key in keyboard to begin insert text, press esc, :wq! in keyboard to save and exit.
    {
      "inbounds": [{
        "port": 18239,
        "protocol": "vmess",
        "settings": {
          "clients": [
            {
              "id": "1a*****-******-*******-*****",
              "level": 1,
              "alterId": 64
            }
          ]
       },
        "streamSettings": {
          "network": "ws",
          "wsSettings": {
            "path": "/MicroCode"   // This path should be same with NGINX settings.
          }
        }
      }],
      "outbounds": [{
        "protocol": "freedom",
        "settings": {}
      },{
        "protocol": "blackhole",
        "settings": {},
        "tag": "blocked"
      }],
      "routing": {
        "rules": [
          {
            "type": "field",
            "ip": ["geoip:private"],
            "outboundTag": "blocked"
          }
        ]
      }
    }
  3. Now restart v2ray with command sudo systemctl restart v2ray.
READ :   How To Install MySQL On Ubuntu

3. Change V2ray Client Tool V2ray Server Configuration.

  1. I use V2RayX as client tool. Click V2RayX icon —> Configure… menu item, then it will popup below dialog. Select one v2ray server in left list, then input the website domain name in the Address text box. The port number is 443. Do not forget open 443 port number in your linux VPS server firewall ( amazon aws or google cloud ). Select ws in the Network drop down list.
    v2rayx v2ray server configuration
  2. Click transport settings… button which locate before Network select list in above window. Then it will popup below dialog. Click WebSocket tab, input the Nginx configuration’s location value ( /MicroCode ) in the path text box. Input “Host”:”your-website-domain-name” in the “headers” text area.
    v2rayx v2ray server ---> transport settings ---> websocket settings
  3. Click TLS tab, check Use TLS checkbox, input your website domain name in the TLS serverName text box. Click OK to save the settings.
    v2rayx v2ray server ---> transport settings ---> tls settings
  4. Now when you connect to the v2ray server, the v2ray client will send ssl request to server 443 port, and the website server will redirect the request to v2ray server.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.