eMonCMS with nGinX

Hi there,

I've setup eMonCMS on a Nginx hosting server. I can see the Login but when trying to register to that new server I can't...

Error log is empty, access.log has only this:

xx.143.141.yy - - [16/Jun/2014:16:22:37 +0200] "-" 400 0 "-" "-"
xx.143.141.yy - - [16/Jun/2014:16:22:37 +0200] "POST /user/register.json HTTP/1.1" 200 2631 "https://my.domain.net/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36"

Here's a Screenshot:

https://www.dropbox.com/s/cudmhu42u7db9gi/Screenshot%202014-06-16%2016.2...

 

Hope you can help...

 

Edit: As I could not make it work on the hosting server I installed another instance on a FreeBSD Jail, after some fiddling I got it to start but end up in exactly the same mess. There's the exact same red bar in the register window...

Robert Wall's picture

Re: eMonCMS with nGinX

I'm no expert on emonCMS, but I would suspect it is a permissions/paths problem with your database engines.

mircsicz's picture

Re: eMonCMS with nGinX

Hi Robert,

I've checked the perm's so many time's I can't imagine it being that simple...

But to double check again, those are the path's I'm aware of:

 

  • EmonCMS install-dir
  • /var/lib/php*

Did I mis one?

 

Greetz

Mircsicz

mircsicz's picture

Re: eMonCMS with nGinX

found a way to make it work:

modified the hints from:

http://www.mylesgray.com/ardunio-hacking/how-to-run-emoncms-on-nginx-and...

and

http://www.ismsolar.com/blog/creando-un-sistema-de-monitorizacion-de-alt...

 

What work's for me on a hosting server with froxlor-admin-panel is this:

server {
    listen xx.xx.xx.xx:80;
    server_name edm.my-domain.de;
    access_log /var/customers/logs/ONE-edm.my-domain.de-access.log combined;
    error_log /var/customers/logs/ONE-edm.my-domain.de-error.log error;
    root /var/customers/webs/ONE/edm.my-domain.de/;
    index index.php index.html index.htm;

    location / {
        rewrite ^/(.*)$ /index.php?q=$1 last;
    }

    location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
        expires 30d;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/nginx/ONE-edm.my-domain.de-php-fpm.socket;
        fastcgi_index index.php;
        include /etc/nginx/fastcgi_params;
    }
}

 

Hope this helps someelse safe some time!

 

Greetz

Mircsicz

simsasaile's picture

Re: eMonCMS with nGinX

Hi,

I'd love to run emonCMS with nginx, and I'm able to run the site and to log in, but some function are still not working.

For example the dial at the dashboard doesn't work and I can't send data to emonCMS via Ethernet and API.

This is my nginx-config:

 

server {
        listen 80;
        listen [::]:80;
        server_name emon.myserver.de;
        ssl_certificate /etc/nginx/ssl/cert.crt;
        ssl_certificate_key /etc/nginx/ssl/key.key;

        root /home/myserver/emoncms/;
         index index.php index.html index.htm;
        # rewrite ^/(.*)$ /index.php?q=$1 last;

        location / {
        rewrite ^/(.*)$ /index.php?q=$1 last;
         root /home/myserver/emoncms/;
        }
         location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
         expires 30d;
         root /home/myserver/emoncms/;
        }
        # To allow POST on static pages
        #error_page  405     =200 $uri;
        #add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE';

        location ~ \.php {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_param  PATH_INFO          $fastcgi_path_info;

              #  fastcgi_pass 127.0.0.1:9000;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param  SCRIPT_FILENAME  /home/myserver/emoncms$fastcgi_script_name;
                include /etc/nginx/fastcgi_params;
                fastcgi_intercept_errors        on;
        }
                # Optional: Don't log access to assets
                access_log off;
}

 

I hope someone has a clue how to get it working!

TrystanLea's picture

Re: eMonCMS with nGinX

Hello simsasaile, I recently tried running emoncms.org on nignx but didnt see a visible performance increase or drop in server load, this was my test sites available configuration:

server {
    listen 80 default_server;
    # listen [::]:80 default_server ipv6only=on;

    root /usr/share/nginx/html/emoncms;
    index index.php index.html index.htm;

    # Make site accessible from http://localhost/
    server_name localhost;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
        # Uncomment to enable naxsi on this location
        # include /etc/nginx/naxsi.rules
                rewrite ^/(.*)$ /index.php?q=$1 last;
    }

        location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
            expires 30d;
            root /usr/share/nginx/html/emoncms;
        }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
    
        # With php5-cgi alone:
        # fastcgi_pass 127.0.0.1:9000;
        # With php5-fpm:
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        }
}

 

 

simsasaile's picture

Re: eMonCMS with nGinX

Hey Trystan,

thank you for sharing your configuration!
I tried it, but it only works at my ubuntu-server with one extra line added in the  location ~ \.php$ { section:

fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

Sadly with this configuration I have still the problem that the dial shows zero. But I found out that the problem is actually that the feeds are marked as inactive and there value is zero too. 

If I open the same emonCMS installation with apache2 it's all working. The reason I'd like to use nginx is that I operate already some sites with nginx, and using nginx would allow me to have emonCMS as an subdomain of my site.

I'd be quite happy, if someone has an Idea how to get it working!

simsasaile's picture

Re: eMonCMS with nGinX

Hey everyone, I solved my problem :)

The problem was, that I still pushed my data to the port where apache was listening. I changed that in emonhub.conf to the port nginx is running, and now I get all the data :)

Thanks again for your help!

engeeaitch's picture

Re: eMonCMS with nGinX

Hi - I'm also trying to get nginx working (I'm using the latest version so that I can take advantage of the security updates).

Here is my config file:

server {
        root /var/www/rpi_thermostat/emoncms;
        index index.php index.html index.htm;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ /index.html;

                rewrite ^/(.*)$ /index.php?q=$1 last;
        }

        location ~ \.php$ {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
        #       # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

        #       # With php5-fpm:
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
        }
}

If comment out the rewrite statement, the login page loads correctly - but I get a login failure when I enter my details.

With the rewrite statement uncommented, the html loads, but the css files and scripts do not load.

I suspect it might be to do with the params file.  Here are my settings:

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_FILENAME         $request_filename;
#fastcgi_param   SCRIPT_FILENAME         $document_root$fastcgi_script_name;
fastcgi_param   SCRIPT_FILENAME         $fastcgi_script_name;
fastcgi_param   SCRIPT_NAME             $fastcgi_script_name;
fastcgi_param   PATH_INFO               $fastcgi_path_info;
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/$nginx_version;

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_param   HTTPS                   $https if_not_empty;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param   REDIRECT_STATUS         200;

Any ideas please?

simsasaile's picture

Re: eMonCMS with nGinX

Hi,

this is the config I'm currently using:

server {
     listen 80;
#     listen 443 ssl;

    #ssl_certificate /etc/nginx/ssl/mycert.crt;
    #ssl_certificate_key /etc/nginx/ssl/mykey.key;

    # Add perfect forward secrecy
    #ssl_ciphers EECDH+AESGCM:EDH+AESGCM:EECDH:EDH:!MD5:!RC4:!LOW:!MEDIUM:!CAMELLIA:!ECDSA:!DES:!DSS:!3DES:!NULL;
    #ssl_prefer_server_ciphers on;

    #Fixing the poodle
    #ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

    root /var/www/rpi_thermostat/emoncms;
    index index.php index.html index.htm;

    # Make site accessible from http://localhost/
    server_name localhost;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
        # Uncomment to enable naxsi on this location
        # include /etc/nginx/naxsi.rules
                rewrite ^/(.*)$ /index.php?q=$1 last;
    }

        location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
            expires 30d;
            root /var/www/rpi_thermostat/emoncms;         }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

        # With php5-cgi alone:
        # fastcgi_pass 127.0.0.1:9000;
        # With php5-fpm:
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        }
}

 

I tested it also with the newest version, so it should work for you. The only thing which is not working are the apps-Modules, maybe we need an extra rewrite rule for that, I don't know. I would be glad if someone has a tip how to get them working too!

Cheers, Simsa

engeeaitch's picture

Re: eMonCMS with nGinX

I finally got this working using the following config file. Note that I used the try statement, rather than the rewrite statement following advice from the nginx wiki (common configuration pitfalls).  Not sure what the "apps-Modules" are but everything seems to be working on my setup.

server {
        listen 80 default_server;

        server_name localhost;

        root /var/www/rpi_thermostat;
        index index.php index.html index.htm;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }

        location /emoncms {
                try_files $uri $uri/ /emoncms/index.php?q=$uri&$args;
        }

        location ~ \.php$ {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
        #       # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

        #       # With php5-fpm:
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
        }
}

 

simsasaile's picture

Re: eMonCMS with nGinX

Hey engeeaitch,

thanks for sharing your improved nginx configuration! 
I tested it now, and with your configuration the apps-moduls (https://github.com/emoncms/app) are working too!

I'm very glad about that!
Many greetings,
Simsa

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.