[ome-users] Nginx 502 Bad Gateway

Chris MacLeod ckm at glencoesoftware.com
Tue Mar 20 18:05:36 GMT 2012


On Mar 20, 2012, at 11:58 AM, Harri Jäälinoja wrote:
> 
> I would prefer to use the standard chkconfig system to start Nginx upon server reboot, so if you have ideas how to fine-tune the config to fit that scenario, please let me know.

Harri,

So depending on how you want nginx setup will depend on the config.

Assuming epel's version of nginx (0.8.55 which is pretty old)

If you are using the stock /etc/nginx/nginx.conf and the /etc/nginx/conf.d directory the following file should work.

--- SNIP ---

    server {
        listen       80;
        server_name  lmu-omero2.biocenter.helsinki.fi;

         # weblitz django apps serve media from here
        location /appmedia {
            alias /opt/OMERO/OMERO.server-Beta-4.3.3/lib/python/omeroweb/media;
        }

        # django's admin media
        location /media {
            alias /opt/OMERO/OMERO.server-Beta-4.3.3/lib/python/omeroweb/media/django_admin_media;
        }

        location / {
            if (-f /opt/OMERO/OMERO.server-Beta-4.3.3/var/maintenance.html) {
               error_page 503 /maintenance.html;
               return 503;
            }
            fastcgi_pass 0.0.0.0:4080;
            fastcgi_param PATH_INFO $fastcgi_script_name;
            fastcgi_param REQUEST_METHOD $request_method;
            fastcgi_param QUERY_STRING $query_string;
            fastcgi_param CONTENT_TYPE $content_type;
            fastcgi_param CONTENT_LENGTH $content_length;
            fastcgi_param SERVER_NAME $server_name;
            fastcgi_param SERVER_PROTOCOL $server_protocol;
            fastcgi_param SERVER_PORT $server_port;
            fastcgi_pass_header Authorization;
            fastcgi_intercept_errors on;
            fastcgi_read_timeout 300;
        }

        location /maintenance.html {
            root /opt/OMERO/OMERO.server-Beta-4.3.3/var;
        }

    }

---- SNIP ---

I have mine named /etc/nginx/conf.d/00_omero.conf (the 00 is to ensure it's loaded before any of the other conf.d files).

By default the nginx.conf file that ships from epel sets up a default virtualhost on port 80 with a server_name of '_', this cause it to catch any undefined server_name and use that virtualhost.  In my example I've set the hostname of the machine so that it will match specifically that hostname.  You can add other aliases by adding them to the server_name line.

Depending on how you want nginx to respond on this machine you can also remove the default server stanza in nginx.conf and either replace it with what I have above or use the conf.d structure to include it and not have to worry about the server_name.  See http://wiki.nginx.org/HttpCoreModule#server_name for further information on server_name within nginx.

Hope that helps.

C






More information about the ome-users mailing list