Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Help with Observium + nginx (rewrite rules)?

rubikrubik Member

Hey All-

I've set up Observium on a VPS and it works great, except for some (most) URLs not working due to using nginx (which isn't officially supported by Observium, per warning in their install guides, etc.)

I really don't want to bother with Apache and I know there are folks here who have it up and working with nginx so I was wondering if anyone would be kind enough to post your nginx/vhost config file portion with your rewrite rules.

The /opt/observium/html/.htaccess file looks like this:

#  DO NOT CHANGE THIS FILE
#  If you need to change this file, you are doing something wrong.

Options FollowSymlinks Multiviews

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\.(js|ico|txt|gif|jpg|png|css|php)
RewriteCond %{REQUEST_URI} !=/server-status
RewriteRule ^(.*)$ index.php/$1/

AcceptPathInfo On

I've tried this in my nginx config file (at the end of the 'try_files' line) but I must be missing something:

location / {
  try_files $uri $uri/ /index.php/$request_uri;
}

Thanks much for any help in advance!

Comments

  • if (!-f $request_filename){
        set $rule_0 1$rule_0;
    }
    if (!-d $request_filename){
        set $rule_0 2$rule_0;
    }
    if ($uri !~ ".(js|ico|txt|gif|jpg|png|css|php)"){
        set $rule_0 3$rule_0;
    }
    if ($uri !~ "=/server-status"){
        set $rule_0 4$rule_0;
    }
    if ($rule_0 = "4321"){
        rewrite ^/(.*)$ /index.php/$1/;
    }
    

    You can use http://www.anilcetin.com/ to convert.

  • I'd highly recommend NOT using that many if statements: http://wiki.nginx.org/IfIsEvil

    Try taking a look @ this: http://pastebin.com/X1hBh2K0

  • nunimnunim Member
    edited March 2014

    I've seen different answers as to the proper settings but this works for me:

     #rewrite for obserivum
            location / {
            try_files $uri $uri/ @observium;
            }
            location @observium {
            rewrite ^(.+)$ /index.php/$1 last;
            }
    
            location ~ \.php {
                            fastcgi_param QUERY_STRING $query_string;
                            fastcgi_param REQUEST_METHOD $request_method;
                            fastcgi_param CONTENT_TYPE $content_type;
                            fastcgi_param CONTENT_LENGTH $content_length;
    
                            fastcgi_param SCRIPT_NAME $fastcgi_script_name;
                            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                            fastcgi_param REQUEST_URI $request_uri;
                            fastcgi_param DOCUMENT_URI $document_uri;
                            fastcgi_param DOCUMENT_ROOT $document_root;
                            fastcgi_param SERVER_PROTOCOL $server_protocol;
    
                            fastcgi_param GATEWAY_INTERFACE CGI/1.1;
                            fastcgi_param SERVER_SOFTWARE nginx;
    
                            fastcgi_param REMOTE_ADDR $remote_addr;
                            fastcgi_param REMOTE_PORT $remote_port;
                            fastcgi_param SERVER_ADDR $server_addr;
                            fastcgi_param SERVER_PORT $server_port;
                            fastcgi_param SERVER_NAME $server_name;
    
                            fastcgi_pass unix:/path/to/php.socket;
                    }
    

    Works great on a 128 SSD RamNode, it's monitoring over 20 devices. I've written most of an Observium + nginx install script but I haven't had the time to properly test it.

Sign In or Register to comment.