nginx conf를 proxypass를 위해 apache conf로 변환하십시오.

Dec 02 2020

이 nginx conf를 apache conf로 변환해야합니다. 내가 변환을 시도했지만 얻지 못했습니다.

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;
}

아파치 conf.

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

하지만 작동하지 않아서 작동 가능하도록 도와주세요. 그리고 나는 상위 업스트림 conf가 무엇인지 그리고 그것을 아파치로 변환하는 방법도 이해하지 못했습니다.

편집하다 :

이 오류가 발생합니다.

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

그리고 나는 이와 같이 도메인의 cpanel conf를 변경하려고 시도했습니다.

<Proxy balancer://apiUpstream/>

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

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

이것을 저장 한 후에는 WHM에서 아파치를 다시 시작할 수 없습니다. Balancer 멤버와 같은 말은로드 할 수 없습니다. 나는 그것을 고치는 방법을 모른다.

스크린 샷

정확한 오류 메시지

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

답변

PawelHawro Dec 13 2020 at 07:08

먼저로드 된 모듈이있는 아파치가 필요합니다.

  • mod_proxy
  • mod_proxy_http
  • mod_proxy_wstunnel (httpd 2.4.5 이상에서 사용 가능) 문서

우분투에서는 다음을 사용하여 활성화 할 수 있습니다.

a2enmod proxy
a2enmod proxy_http
a2enmod proxy_wstunnel

노드 앱의 웹 소켓에 연결해야하는 WebSocket에 연결하려고합니다.

다음과 같이 시도하십시오.

<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>