As I do pi (and for that matter, PC) related projects, I keep notes. Didn't do this as a younger guy, when I "understood instantly and remembered forever" - but I'm not that guy anymore. I'm the poor slob who might have to modify it and/or make it work again long after I've forgotten all the details. This is like putting good comments in code, but in this case, it's sysadmin stuff - it's how-to put things in and get them working. I've probably put this up before, but it deserves notice, as it's the fastest/easiest way to get NGINX web serving going on in a pi - and it's a far better server than Apache unless you have invested tons in being an Apache expert - different, simpler, faster, lighter, does all the same stuff, only better.
Here's my own notes for my favorite sysadmin:
- Code: Select all
NGINX
installed mods for php and perl cgi's
(perl CGI's end with .pl)
/etc/nginx/nginx.conf
/etc/nginx/sites-available/default
Our content is located at /usr/share/nginx/www/
Do the tutorial above, in order - copying these files won't work unless the prerequisites are there, but here are the important ones for reference (and you can cut-paste from these while doing the tutorial).
This is /etc/nginx/sites-available/default:
- Code: Select all
# You may add here your
# server {
# ...
# }
# statements for each of your virtual hosts to this file
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##
server {
#listen 80; ## listen for ipv4; this line is default and implied
#listen [::]:80 default_server ipv6only=on; ## listen for ipv6
root /usr/share/nginx/www;
index index.php index.cgi 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/ /index.html;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
allow ::1;
deny all;
}
# Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
#location /RequestDenied {
# proxy_pass http://127.0.0.1:8080;
#}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
#error_page 500 502 503 504 /50x.html;
#location = /50x.html {
# root /usr/share/nginx/www;
#}
# 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;
}
location ~ \.pl|cgi$ {
try_files $uri =404;
gzip off;
fastcgi_pass 127.0.0.1:8999;
fastcgi_index index.pl;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# root html;
# index index.html index.htm;
#
# location / {
# try_files $uri $uri/ =404;
# }
#}
# HTTPS server
#
#server {
# listen 443;
# server_name localhost;
#
# root html;
# index index.html index.htm;
#
# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
#
# ssl_session_timeout 5m;
#
# ssl_protocols SSLv3 TLSv1;
# ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP;
# ssl_prefer_server_ciphers on;
#
# location / {
# try_files $uri $uri/ =404;
# }
#}
For fairly ridiculous reasons, I'm going to put a Pi in my battery box. Those reasons are - there is ethernet cable buried ?? years ago going there - and we want galvanic isolation for millivolt measurements at a current shunt, and well, I have a spare older pi (the new model 2 version will spoil you instantly) - so why not? Using the general scheme I've been using that slaves arduino's off pi's - I can later add the one that's going to control the Listeroid diesel backup generator, and of course, have CGI's etc for control, status, and manual over-ride of whatever I have this do automatically. To ID the pi to any user of tightVNC, I used this as its desktop pic:
I've added tellem and tellme from my landns thing to all my machines here, so once things have been up over a minute or two, you can just use machine names in browsers and vnc viewers etc. In the case of the pi, I started tellem and tellme from /etc/rc.local after just copying them to /usr/bin and doing a sudo chmod 6711 to them both. Since they daemonize, all you have to do is put for example /usr/bin/tellem in /etc/rc.local and that all works fine. The installer I originally put up has fallen afoul of the fight between sysV init and systemD on some machines, sigh. (It still works on most pc's with most linuxes).
This particular pi wants to be able to use a Dallas DS18B20 (sealed up as a soil temperature monitor) for battery temperature (redundant with the Xantrex stuff I can't scrape data from, darn).
So, here's the cheat-sheet for that:
- Code: Select all
DS18B20 on pi
in /boot/config.txt, add
dtoverlay=w1-gpio
in /etc/modules, add
w1-gpio
w1-therm
reboot, then:
cd /sys/bus/w1/devices
ls
cd 28-xxxx (change this to match what serial number pops up)
cat w1_slave
Two lines are output. First one ends in "YES" if it's good data, second one
ends in t=##### (degrees C x 1000)
I also want perl's Device::SMBus to talk to an I2C a/d converter for battery voltage and differential on the current shunt (which I'll have a detailed post about once it's installed and working).
Here's the skinny on that - and I will have to rewrite an arduino library to work on the pi with this AD1015 device. No big deal I hope.
- Code: Select all
For I2c:
sudo cpanm Dev::SMBus
Added i2c-dev and i2c-bcm2708 to /etc/modules
Added dependencies for perl Device::SMBus: i2c-tools libi2c-dev (which installs easier if you do this first?)
The magic words are: sudo i2cdetect -y 1
The above lists all detected i2c device addresses.
Handy link on pi i2c from Adafruit.
Note, for perl modules, install cpanminus and say sudo cpanm module::name...it works a lot easier than other ways, and the name is the same as on CPAN.
eg say sudo cpanm Device::SMBus - and it will happen, including nearly all dependencies (nothing is quite perfect, I'm sure you understand).
I always install synaptic (sudo apt-get synaptic) as one of the very first things I do, as I like to be able to search rather than just blindly copy "apt-get" lines from web pages. It's also really good at removing stuff - like the pi noob stuff (wolfram, scratch, games, silly things that eat space and I never use) - including their dependencies, making your basic image a lot tighter. To install what is invoked as cpanm above, you install cpanminus (which is why I use cpanminus - names in synpatic aren't the same as on CPAN).
Of course, if you're just fishing around, you want this link for CPAN.
Most perl modules are in just plain perl - so they work on pi as is. Some require some C libraries to be built, and still probably work on pi. Device::SerialPort is another biggie that does (as does GnuplotIF if you use Gnuplot-x11), but it requires you use sudo raspi-config to free up the pi's serial hardware as just a port first (and add yourself to dialup group if you haven't). At some point if you haven't, you'll have to install build-essentials (from apt-get or synaptic). Most of the other package installers figure this out and do it for you - there's a version of gcc that works for ARM.