V2Ray中Apache的配置与匹配

最近在我的服务器中搭配了V2Ray+WebSocket+TLS+Nginx,成功倒是成功了。但是我的服务器在之前就用Apache+mediawiki搭建了一个百科,这两者冲突了。

于是我先试着把V2Ray中的Nginx换成Apache,我首先参考了https://github.com/v2ray/v2ray-core/issues/747,关掉Nginx,然后在Apache配置文件中加入这段

    

    ServerName subdomain.yourdomain.com
    ServerAlias subdomain.yourdomain.com
    ##SSL Engine Switch:
    #Enable/Disable SSL for this virtual host.
    SSLEngine On

    RewriteEngine On
    RewriteCond %{HTTP:Upgrade} =websocket [NC]
    RewriteRule /(.*)           ws://localhost:3579/$1 [P,L]
    RewriteCond %{HTTP:Upgrade} !=websocket [NC]
    RewriteRule /(.*)           http://localhost:3579/$1 [P,L]

    ##Proxy to port 3579
    SSLProxyEngine On
    Proxypass /ray http://127.0.0.1:3579
    ProxyPassReverse /ray http://127.0.0.1:3579
    SSLCertificateFile /etc/v2ray/v2ray.crt
    SSLCertificateKeyFile /etc/v2ray/v2ray.key

    

但是因为我的mediawiki中还有.htaccess文件,结果上面的配置和.htaccess发生了冲突。

仔细检查后,发现是上面那段配置中有一行错误,那就是

    RewriteCond %{HTTP:Upgrade} !=websocket [NC]
    RewriteRule /(.*)           http://localhost:3579/$1 [P,L]

这里的意思应该是,非websocket请求则进入正常请求,结果这块还是照样进入了3579端口里。

我试图修改匹配规则,但是修改半天还是冲突,干脆直接删掉这两行,结果居然就正常了。可能是直接跳过这块的匹配,进.htaccess里面匹配去了

正确配置

    

    ServerName subdomain.yourdomain.com
    ServerAlias subdomain.yourdomain.com
    ##SSL Engine Switch:
    #Enable/Disable SSL for this virtual host.
    SSLEngine On

    RewriteEngine On
    RewriteCond %{HTTP:Upgrade} =websocket [NC]
    RewriteRule /(.*)           ws://localhost:3579/$1 [P,L] # 注意该处的端口与v2ray的端口一致
    # RewriteCond %{HTTP:Upgrade} !=websocket [NC]
    # RewriteRule /(.*)           http://localhost/$1 [P,L] # 自己的域名

    ##Proxy to port 3579
    SSLProxyEngine On
    Proxypass /ray http://127.0.0.1:3579
    ProxyPassReverse /ray http://127.0.0.1:3579
    SSLCertificateFile /etc/v2ray/v2ray.crt
    SSLCertificateKeyFile /etc/v2ray/v2ray.key

    

 

你可能感兴趣的:(mediawiki,apache,服务器,nginx,http)