502 Bad Gateway Archives - Justin Silver https://www.justinsilver.com/tag/502-bad-gateway/ Technology, Travel, and Pictures Fri, 01 Mar 2019 18:00:40 +0000 en-US hourly 1 https://wordpress.org/?v=6.0.1 https://www.justinsilver.com/wp-content/uploads/2013/06/cropped-apple-touch-icon-160x160.png 502 Bad Gateway Archives - Justin Silver https://www.justinsilver.com/tag/502-bad-gateway/ 32 32 502 Bad Gateway on NGINX with BuddyPress https://www.justinsilver.com/technology/linux/502-bad-gateway-nginx-buddypress/?utm_source=rss&utm_medium=rss&utm_campaign=502-bad-gateway-nginx-buddypress https://www.justinsilver.com/technology/linux/502-bad-gateway-nginx-buddypress/#comments Thu, 28 Mar 2013 02:12:53 +0000 http://justin.ag/?p=2983 I recently switched over from Apache to NGINX for my WordPress hosting, and it was surprisingly easier than I expected. Alongside the W3 Total Cache plugin to handle my minification and object/db caching my...

The post 502 Bad Gateway on NGINX with BuddyPress appeared first on Justin Silver.

]]>
AmpedSense.OptimizeAdSpot('AP'); AmpedSense.OptimizeAdSpot('IL'); AmpedSense.OptimizeAdSpot('IR');

I recently switched over from Apache to NGINX for my WordPress hosting, and it was surprisingly easier than I expected. Alongside the W3 Total Cache plugin to handle my minification and object/db caching my sites are blazing fast. The one problem I did run into was random 502 errors on some pages. The fix was to update the server{} block of nginx.conf to include parameters for proxy_* buffers and fastcgi_* buffers. In my configuration this is in an include file so that it can be easily imported into all the different servers that I run on this host.

My full configuration for WordPress (which also supports pretty URLs, MultiSite, BuddyPress, and WooCommerce) is:

# Use the Nginx-Helper plugin to automatically generate this map
# https://wordpress.org/plugins/nginx-helper/
map $http_host $blogid {
    default                         0;
    include /var/www/example.com/html/wp-content/uploads/nginx-helper/map.conf;
}

server {
    # accept connections on all IP addresses, port 80
    listen                          80;

    # listing on SSL port 443?
    #listen                         443 ssl;
    #ssl                            on;
    #ssl_certificate                /etc/nginx/ssl/example.com.crt;
    #ssl_certificate_key            /etc/nginx/ssl/example.com.key;

    # name this server
    server_name                     example.com www.example.com;

    # set the root folder for web files
    root                            /var/www/example.com/html;

    # MultiSite Configuration ################

        # avoid PHP readfile()
        location ^~ /blogs.dir {
            internal;
            alias                       /var/www/com.rovair/www/html/wp-content/blogs.dir;
            access_log                  off;
            log_not_found               off;
            expires                     max;
        }

        # WPMU files
        location ~ ^/files/(.*)$ {
            try_files                   /wp-content/blogs.dir/$blogid/$uri /wp-includes/ms-files.php?file=$1;
            access_log                  off;
            log_not_found               off;
            expires                     max;
        }

    # End MultiSite Configuration ############

    index                           index.php;

    # serve static files and send everything else to WordPress
    try_files $uri $uri/ /index.php?$args;

    # send PHP requests to fastcgi (uses spawn-fcgi)
    location ~ \.php$ {
        # zero-day exploit defense.
        try_files                       $uri =404;

        # performance boosts for PHP
        sendfile                        on;
        tcp_nopush                      off;
        keepalive_requests              0;

        # proxy buffers - no 502 errors!
        proxy_buffer_size               128k;
        proxy_buffers                   4 256k;
        proxy_busy_buffers_size         256k;

        # fastcgi buffers - no 502 errors!
        fastcgi_buffering               on;
        fastcgi_buffer_size             16k;
        fastcgi_buffers                 16 16k;

        # max timeouts (should match php.ini)
        fastcgi_connect_timeout         600s;
        fastcgi_send_timeout            600s;
        fastcgi_read_timeout            600s;

        # index page
        fastcgi_index                   index.php;

        # pass request to fastcgi/php-cgi via spawn-fcgi
        fastcgi_pass                    localhost:53217;

        # default fastcgi_params
        include                         fastcgi_params;

        # override fastcgi_params
        fastcgi_param                   SERVER_NAME $host;
        fastcgi_param                   SCRIPT_FILENAME $document_root$fastcgi_script_name;

        break;
    }
}

Some quick notes:

  • The various buffer parameters prevent semi-random 502 errors, for example trying to logout of a BuddyPress site always resulted in a 502, and remaining logged in
  • try_files will test to see if a file/directory exists and if not passes it off to WordPress’ index.php file – the ?$args at the end is important for WordPress to receive the entire $_REQUEST

The post 502 Bad Gateway on NGINX with BuddyPress appeared first on Justin Silver.

]]>
https://www.justinsilver.com/technology/linux/502-bad-gateway-nginx-buddypress/feed/ 1
SVN COPY 502 Bad Gateway Error https://www.justinsilver.com/technology/svn-copy-502-bad-gateway-error/?utm_source=rss&utm_medium=rss&utm_campaign=svn-copy-502-bad-gateway-error https://www.justinsilver.com/technology/svn-copy-502-bad-gateway-error/#respond Fri, 02 Nov 2012 19:01:06 +0000 http://justin.ag/?p=2700 There is a lot of info to be found on the Internet about the “502 Bad Gateway Error” when trying trying to move a directory or files when your repository is hosted on Apache...

The post SVN COPY 502 Bad Gateway Error appeared first on Justin Silver.

]]>
AmpedSense.OptimizeAdSpot('AP'); AmpedSense.OptimizeAdSpot('IL'); AmpedSense.OptimizeAdSpot('IR');

There is a lot of info to be found on the Internet about the “502 Bad Gateway Error” when trying trying to move a directory or files when your repository is hosted on Apache using SSL and WEBDAV. In a nutshell Apache is confused by the COPY command and things you are trying to make a move between HTTP and HTTPS, or in other words, a different host. You can read up on the problem here: http://www.science.uva.nl/research/air/wiki/Subversion502BadGateway

The problem that I ran into was with my HTTP server on the same host. Why do I need an HTTP server you may ask? Well, mainly to redirect requests from http://svn.example.com to https://svn.example.com. Most of the documentation I was able to find on this suggested simply adding a line to the VirtualHost to update the header, like so:

RequestHeader edit Destination ^https http early

In my case, this just wasn’t working. What did fix it is a bit counter-intuitive – I had to enable the SSLEngine on my HTTP VirtualHost, as well as my HTTPS VirtualHost. My configuration now looks like the following, and I am able to move files again.

SSLCertificateFile /etc/httpd/ssl/self-signed.crt
SSLCertificateKeyFile /etc/httpd/ssl/self-signed.key

<VirtualHost *:80>
        ServerName svn.example.com
        RequestHeader edit Destination ^https http early

        # Turn mod_ssl on even though we are on 80
        SSLEngine on

        # Rewrite HTTP to HTTPS
        RewriteEngine On
        RewriteCond %{HTTPS} off
        RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</VirtualHost>

<VirtualHost *:443>
        ServerName svn.example.com

        # Turn mod_ssl on
        SSLEngine on

        <Location "/">
                DAV svn
                SVNPath /var/svn/repository
                AuthzSVNAccessFile /var/svn/repository/conf/authz

                AuthType Basic
                AuthName "example.com"
                AuthUserFile /var/svn/.htauthfile
                Require valid-user
        </Location>
</VirtualHost>

The post SVN COPY 502 Bad Gateway Error appeared first on Justin Silver.

]]>
https://www.justinsilver.com/technology/svn-copy-502-bad-gateway-error/feed/ 0