OMV – WordPress and NGINX – a further update

I was struggling with WordPress and permalinks.  The prior onfiguration I had developed worked fine until I switched to permalinks and then it seems to be picked up the js css etc from the root and not the alias.

Google is wonderful as I found this site – http://www.netz39.de/2014/installation-of-wordpress-in-a-subdirectory-with-nginx/.

I thought it was something to do with the way the try_files was working in relation to fastcgi.  It was.

So the wordpress config was update to be as below.  Note the location rewrite needs to be at the server level.

 

location @wordpress_rewrite {
rewrite ^/wordpress/(.*)$ /wordpress/index.php?$1;
}

location /wordpress {
alias /media/13eaa8c9-07ee-4dfc-9d1b-adfae0f0248d/www/wordpress;

add_header Content-Security-Policy "default-src 'self' https: data: 'unsafe-inline' 'unsafe-eval';" always;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
add_header X-Download-Options noopen;
add_header X-Permitted-Cross-Domain-Policies none;

index index.php;
try_files $uri $uri/ @wordpress_rewrite;

location ~* /wordpress/(?:uploads|files)/.*\.php$ {
deny all;
}

location ~ ^/wordpress/(.+\.php)$ {
alias                           /media/13eaa8c9-07ee-4dfc-9d1b-adfae0f0248d/www/wordpress/$1;
fastcgi_split_path_info         ^(.+\.php)(/.*)$;
include fastcgi.conf;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass unix:/var/run/fpm-19e311b1-25e1-4257-8dbc-d49c5ec59015.sock;
}

location = /wordpress/favicon.ico {
access_log off;
log_not_found off;
}

location = /wordpress/robots.txt {
allow all;
access_log off;
log_not_found off;
}

location ~ /wordpress/\. {
deny all;
}

location ~* /wordpress/(?:config)/.*\.php$ {
deny all;
}

location ~* /wordpress/\.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
}

Owntracks and Mosquitto

Came across Owntracks and decided that it would be fun to have my own Mosquitto repository.

Followed instructions here ….
https://www.digitalocean.com/community/questions/how-to-setup-a-mosquitto-mqtt-server-and-receive-data-from-owntracks

They work fine with the exception of needing to install mosquitto-clients to get the mosquitto_sub command working and leaving off the ip address in the mosquitto.conf file from the listener entry. Looking at the log later on the connection is from the ip address of the router on the local lan for external connections and that probably was the address needed to get things working if an ip address was used.

So when I tested and changed the location and config items multiple items are written to the mosquitto database. This then looks bad in the recorder as there are loads of entries which don’t look pretty!
These are in var / spool / owntracks / recorder / store and then either last or rec. If you remove all entries except the ones you want from both then things look pretty again.

It is also worth installing mqtt-spy from mqhive – http://kamilfb.github.io/mqtt-spy/ and publishing a null record without any data or retain so that the mosquitto database does not have then entries any more.

the mosquitto database is normally in var/lib/mosquitto but the location can be changed in the mosquitto.conf or conf.d file in etc/mosquitto.

Now it got tricker when I wanted to publish the steps from my iPhone. Publishing a command did nothing.  I found this comment on GitHub …. ”

Remote commands need to be enabled with remoteConfig: export your configuration, add cmd: true, and re-import (e.g. by sending the .otrc file to iOS and open in OwnTracks).

Once you’ve done that, you can send remote commands. Note though, that the iOS app is put to sleep by the OS which means that when it’s in the background you will have to wait until it wakes up for the command to take effect / be processed; this can take a while. Hence we suggest you post commands to iOS with QoS=2″

So I did this and all is well.

mosquitto_pub -q 2 -h xxxx -p 8883 -t owntracks/owntracks/michael-iPhone6s/cmd -u owntracks -P xxx -m ‘{“_type” : “cmd”, “action”: “reportSteps”}’

and this opened the BBC new in the Featured tab.  Cool….

mosquitto_pub -q 2 -h xxx -p 8883 -t owntracks/owntracks/michael-iPhone6s/cmd -u owntracks -P xxx -m ‘{“action”: “action”, “url”: “http://news.bbc.co.uk”, “_type”: “cmd”}’

I was a bit puzzled about why the topic was owntracks/owntracks but on further reading of the documentation the default topic is owntracks/username/devicename and as I was using a username of owntracks the second pat of the topic derived from that.

Re-naming a table in MyWebSQL

So this was trickier than I thought.

I have a .sql dump of a database and when I imported it it was saved as wordpressblog.

I wanted it to be naylorfamily.

There is no rename function and so I needed to revert back to the command line and did it like this

mysql -u xxxxx -p"xxxxxx" wordpress -sNe 'show tables' | while read table; do mysql -u xxxxx -p"xxxxxx" -sNe "RENAME TABLE wordpress.$table TO naylorfamily.$table"; done