大网数据广告活动
服务器运维问答

502 from Apache over HTTPS with reverse proxy to Node server on different port

· 52CE 我爱测

I have a node application running on port 3030 for an API which I want to access over HTTPS. If I visit http://api.example.com:3030/ *** I can load a 200 response with no problem so the node application is definitely running, how…

问题原文

原帖链接 · Robert · CC BY-SA 4.0

I have a node application running on port 3030 for an API which I want to access over HTTPS.

If I visit http://api.example.com:3030/*** I can load a 200 response with no problem so the node application is definitely running, however if I visit https://api.example.com/**** I get the following error in the browser:

Proxy Error
The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request GET /api/posts.

and the following in the apache error log:

[Sun Jun 03 15:30:47.942229 2018] [proxy_http:error] [pid 30884] (103)Software caused connection abort: [client xx.xx.xx.xx:xxxxx] AH01102: error reading status line from remote server api.example.com:3030
[Sun Jun 03 15:30:47.942414 2018] [proxy:error] [pid 30884] [client xx.xx.xx.xx:xxxxx] AH00898: Error reading from remote server returned by /***

This is my Apache config:

<IfModule mod_ssl.c>
<VirtualHost *:443>
        ServerName www.api.example.com
        ServerAlias api.example.com
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/xxxxxx/

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

<Directory /var/www/html/xxxxxx/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
RewriteEngine on

SetEnv proxy-initial-not-pooled 1
SSLEngine On
SSLProxyEngine on
SSLCertificateFile /etc/letsencrypt/live/example.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem
ProxyPreserveHost On
ProxyPass / https://api.example.com:3030/
ProxyPassReverse / https://api.example.com:3030/

</VirtualHost>
</IfModule>

Versions of Apache and Node:

  • node 8.11.2
  • Apache 2.4.7

Any support is greatly appreciated, thanks.

已采纳解答

原帖链接 · Gerald Schneider · CC BY-SA 4.0

Your nodejs expects HTTP on it's port, as is evident by your working test:

If I visit http://api.example.com:3030/ I can load a 200 response with no problem

But you configured your Apache to access it via https

ProxyPass / https://api.example.com:3030/
ProxyPassReverse / https://api.example.com:3030/

Change your Apache configuration to use http and it will work.

ProxyPass / http://api.example.com:3030/
ProxyPassReverse / http://api.example.com:3030/

An additional note:
It is common practice not to make the ports of application servers public. You should configure nodejs to only listen on your loopback device (127.0.0.1) and then change your Proxy directives to connect to localhost:3030 instead of api.example.com.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-06-03)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。