Report this

What is the reason for this report?

Getting ERR_ABORTED 502 (Proxy Error) using apache, node.js express and socket.io

Posted on June 19, 2020

Hi there, Im having a problem with proxy on apache, when i run my app and upload several images i get no error but when using bigger files such as .mp4 files (50mb), the first files upload without a problem but then if it’s several files I get: ERR_ABORTED 502 (Proxy Error)

My config file for my domain is:

        ServerAdmin info@domain.net
        DocumentRoot /var/www/domain.net/public_html
        ServerName domain.net
        ServerAlias www.domain.net

        ProxyPreserveHost On
        ProxyPass / http://127.0.0.1:3002/
        Alias /error/ “/var/www/domain.net/public_html/error/”
        ProxyPass /error/ !
        ErrorDocument 503 /error/503.html
        ProxyPassReverse / http://127.0.0.1:3002/

        RewriteEngine On
        RewriteCond %{REQUEST_URI}  ^/socket.io            [NC]
        RewriteCond %{QUERY_STRING} transport=websocket    [NC]
        RewriteRule /(.*)           ws://localhost:3002/$1 [P,L]

        <Directory /var/www/domain.net/public_html/>
                Options FollowSymLinks
                AllowOverride all
                Require all granted
        </Directory>

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        ErrorDocument 503 /50x.html

        <Files "50x.html">
                <If "-z %{ENV:REDIRECT_STATUS}">
                        RedirectMatch 404 ^/50x.html$
                </If>
        </Files>

Any ideas or help? Thanks.



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Heya,

The 502 Proxy Error means that the proxy server, in your case Apache, received an invalid response from an upstream server it accessed to fulfill the request. This could be happening for a number of reasons.

  1. Timeout Issue: The default proxy timeout configuration for Apache might be too low for large file uploads. Try increasing the timeout for your ProxyPass directive:
ProxyPass / http://127.0.0.1:3002/ timeout=600
ProxyPassReverse / http://127.0.0.1:3002/

Here, the timeout is set to 600 seconds (10 minutes). You may adjust this to fit your needs.

  1. Client Maximum Body Size: Ensure that the file size of your uploads doesn’t exceed the configured maximum size limit.

  2. Check Your Application Server: Make sure that your Node.js server is not crashing or becoming unresponsive when you’re uploading large files. Look at the logs for your Node.js server to see if there are any error messages.

  3. Check Apache and System Logs: Inspect the Apache error log file located typically in /var/log/apache2/error.log (or as defined in your configuration) and system logs in /var/log/syslog for any indications of what might be causing the 502 error.

  4. Use Mod_reqtimeout Module: The Apache mod_reqtimeout module allows you to control the timeout based on the bytes transferred over the time rather than an absolute time since the request started. You can enable this module with a2enmod reqtimeout and then configure the timeouts with the RequestReadTimeout directive.

Remember to restart your Apache server after making any changes to the configuration:

sudo systemctl restart apache2

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.