sunergos
sunergos

Reputation: 128

Nuxt with Apache2 returns 502 Proxy Error: Error reading from remote server

I have VPS with Ubuntu 18.04 and Apache 2.4.29. When I run npm run start everything works If I'm accessing my page through http://example.com.

I installed Let's Encrypt certificate, enabled https in nuxt.config.js so now nuxt's listening on https://example.com.

My example.com-le-ssl.conf in sites-available folder of Apache looks like this:

<IfModule mod_ssl.c>
<VirtualHost *:443>
        ServerAdmin [email protected]
        DocumentRoot /var/www/example.com

        ServerName example.com
        ServerAlias www.example.com

        SSLEngine On
        SSLProxyEngine On

        ProxyPreserveHost On
        ProxyPass / https://123.123.12.123:3000/
        ProxyPassReverse / https://123.123.12.123:3000/

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

        Include /etc/letsencrypt/options-ssl-apache.conf
        SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem

</VirtualHost>
</IfModule>

When accessing https://example.com it returns 502 Proxy Error:

Proxy Error

The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request

Reason: Error reading from remote server

Apache/2.4.29 (Ubuntu) Server at example.com Port 443

Is it problem with nuxt, or with some other Apache settings? Or something with certificate? But https works if I don't use ProxyPass with port 3000 and I'm not running nuxt app. So https://example.com works, but not when I try to start nuxt on port 3000 and use ProxyPass to use backend server.

My error.log file:

[Thu Aug 13 14:11:12.935753 2020] [proxy:error] [pid 22355:tid 140240589145856] [client 87.197.115.218:63122] AH00898: Error reading from remote server returned by /
[Thu Aug 13 14:11:13.009134 2020] [proxy_http:error] [pid 22355:tid 140240580753152] (103)Software caused connection abort: [client 87.197.115.218:63122] AH01102: error reading status line from remote server 123.123.12.123:3000

Upvotes: 0

Views: 2338

Answers (1)

sunergos
sunergos

Reputation: 128

The problem was that I enabled https in nuxt.config.js and then in example.com-le-ssl.conf used ProxyPass to that https. The solution for me was to start nuxt on http and also change https to http in my example.com-le-ssl.conf file.

Upvotes: 0

Related Questions