convert nginx conf to apache conf for proxypass

北城以北 提交于 2021-02-08 02:33:16

问题


I need to convert this nginx conf to apache conf. As i have tried to convert, But failed to get it.

upstream apiUpstream {

  # 1. Set your port here
  server 127.0.0.1:8080;
  keepalive 64;
}

server {
  listen 80;
  listen 443 ssl;

  # 2. Set your API domain name here
  server_name yourdomain.com;

  location / {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # RequestHeader set X-Forwarded-Port "443"
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $http_host;

    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_pass http://apiUpstream/;  
    proxy_redirect off;
    proxy_read_timeout 240s;
  }

  # 3. SSL certificate set below
  # Here is added a sample certificate format of letsencrypt
  # You are free to remove it and configure yours here
  ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;
  include /etc/letsencrypt/options-ssl-nginx.conf;
  ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}

To apache conf.

  ProxyRequests On
  ProxyPass   http://apiUpstream/ timeout=240
  ProxyPassReverse http://apiUpstream.com

But its not working, Help me to make it workable.And I didn't understand whats top upstream conf and how to convert it to apache as well.

Edit :

I am getting this error

peerjs.min.js:52 WebSocket connection to 'wss://api.example.com/peer/peerjs?key=peerjs&id=6yqD1MoKzkK&token=kp8g8w6pj2l' failed: Error during WebSocket handshake: 'Connection' header is missing

And I have tried to change the cpanel conf for the domain like this.

<Proxy balancer://apiUpstream/>

 BalancerMember http:// 127.0.0.1:8080;
 keepalive 64;
 ProxySet lbmethod=byrequests
</Proxy>

ProxyRequests On
ProxyPass / balancer://apiUpstream/
ProxyPassReverse / balancer://apiUpstream/

After saving this I can't restart apache from WHM. its saying like the Balancer member cant be loaded. I don't know how to fix it.

Screenshot

and exact error message

Syntax error on line 2 of /etc/apache2/conf.d/userdata/ssl/2_4/node/api.example.com/proxy_pass.conf: Dec 07 12:03:54 
ip-xx-xx-xxx-xx.ip.secureserver.net restartsrv_httpd[32106]: BalancerMember can not have a balancer name when defined in a location Dec 07 12:03:54

回答1:


First of all you need apache with loaded modules:

  • mod_proxy
  • mod_proxy_http
  • mod_proxy_wstunnel (available in httpd 2.4.5 and later) docs

In ubuntu you can enable this with:

a2enmod proxy
a2enmod proxy_http
a2enmod proxy_wstunnel

You are trying to connect to WebSocket you need to got to websocket of your node app.

Try something like this:

<VirtualHost *:443>
  ServerName example.com
      
  ProxyPreserveHost On
  RewriteEngine On
     
  # If header Upgrade: websocket found, proxy to ws
  RewriteCond %{HTTP:Upgrade} =websocket [NC]  
  RewriteRule /(.*)           ws://localhost:8080/$1 [P,L]  
  
  # If header not found use http
  RewriteCond %{HTTP:Upgrade} !=websocket [NC]
  RewriteRule /(.*)           http://localhost:8080/$1 [P,L]

  
  # SSL config
  ...
  
</VirtualHost>


来源:https://stackoverflow.com/questions/65102311/convert-nginx-conf-to-apache-conf-for-proxypass

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!