With my move to a better VPS, I changed some things on 0paste:
- MRI Ruby 1.9.3
- Passenger
Worked quite well and much easier to maintain.
With my move to a better VPS, I changed some things on 0paste:
Worked quite well and much easier to maintain.
If you didn’t know, the current moebooru running on oreno.imouto is using ancient version of many things. It also uses a custom lighty module (mod_zipfile) which doesn’t seem to be available anywhere.
I’ve updated it with latest Rails 2.x and made it compatible with nginx. Mostly. You can see it running here.
The plans:
We’ll see if I can actually finish this one. Grab the source here. Yeah, I’m using Mercurial for a Rails project.
During my migration to other server, I recreated some of my configs and enabled gzip compression for most file types. Here’s the relevant config:
gzip on; gzip_vary on; gzip_disable "msie6"; gzip_comp_level 6; gzip_proxied expired no-cache no-store private auth; gzip_types text/plain text/xml application/xml application/json application/x-javascript text/javascript text/css;
It should cover most text-based content one will ever serve over the web. Probably.
This morning I noticed I haven’t upgraded WordPress MU Domain Mapping plugin to the latest version. It supposedly brings better SSL support. And after upgrading I couldn’t log in to my mapped domain blogs (e.g. this blog). Wasn’t it a great way to start my morning?
After some digging, I found out the problem was because I don’t have one PHP(?) parameter – HTTPS – passed properly. It should set to True whenever one is using SSL connection otherwise there’s no way the PHP process can know if the connection is secure or not. Previous version of WPMUDM have a bug in which skips SSL check but in turn enables using HTTPS even without such parameter. Decided it’s my fault (I believe it would completely breaks phpMyAdmin), adding the parameter then I did.
But it’s not that simple: I’m using unified config for both my SSL and non-SSL connection’s PHP include. Splitting the config would make the duplication worse (it’s already relatively bad as it is) so that’s not an option. Using the evil if is also not a solution since it doesn’t support setting fastcgi_param inside it.
Then the solution hit me. The map module – a module specifically made for things like this and to avoid usage of if. I tested it and indeed worked as expected.
Here be the config:
...
http {
...
map $scheme $fastcgi_https {
https 1;
default 0;
}
...
server {
...
location ~ .php$ {
...
fastcgi_param HTTPS $fastcgi_https;
}
...
And WordPress MU Domain Mapping is now happy.
Update 2012-02-20: nginx version 1.1.11 and up now have $https variable. No need to have that map anymore.
Test post to see if this plugin actually works.
Here be the magical line:
try_files /wp-content/w3tc-$host/pgcache/$uri/_index.html $uri $uri/ /index.php?q=$uri&$args;
Doesn’t use gzip, css, etc yet.
WordPress Multisite, previously known as WordPress MU (Multi User), is an application which allows hosting multiple WordPress blogs with just one installation. Instead of creating copies of WordPress for each users’ blogs, one can use one installation of Multisite to be used by multiple users, each with their own blogs. Personal/custom domain is also possible as used for this blog (this blog’s master site is genshiken-itb.org). Too bad, the official documentation only provided guide for installing on Apache. If you haven’t known, I usually avoid Apache – I simply more proficient with nginx. Of course, this blog is also running on nginx therefore it’s perfectly possible to run WordPress Multisite on nginx.
At any rate, reading the official documentation is still a must and this post will only cover the nginx version of Apache-specific parts (namely Apache Virtual Hosts and Mod Rewrite and .htaccess and Mod Rewrite) and only for subdomain install. Subdirectory one will or will not follow some time later.
Assuming you have working nginx and php-cgi (with process manager like php-fpm or supervisord), for starter you’ll want to create a specific file for this WP install. Let’s say this file named app-wordpress.conf. Obviously you have put WordPress installation somewhere in your server. In this example I put the files in /srv/http/genshiken-itb.org/.php/wordpress. Its content:
client_max_body_size 100m;
root /srv/http/genshiken-itb.org;
location /. { return 404; }
location / {
root /srv/http/genshiken-itb.org/.php/wordpress;
index index.php;
try_files $uri $uri/ /index.php?$args;
rewrite ^/files/(.*) /wp-includes/ms-files.php?file=$1;
location ~ .php$ {
try_files $uri =404;
fastcgi_pass unix:/tmp/php-genshiken.sock;
fastcgi_read_timeout 600;
fastcgi_send_timeout 600;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
}
Simple enough. Actually, it’s exact same with normal WordPress install except one extra line:
rewrite ^/files/(.*) /wp-includes/ms-files.php?file=$1;
And you’re set. Note that I set fastcgi timeouts higher than default to work around the slow performance of Amazon EC2 Micro Instance. Should only needed on network upgrade and massive blog import.
Anyway, in your main nginx.conf file, put:
server {
listen 80;
server_name *.genshiken-itb.org;
include app-wordpress.conf;
}
In proper place. The usefulness of separate file for WordPress configuration will become apparent once you want to tweak performance for some blogs. I’ll explain that later if I feel like to.
If you happen to be in no-www camp and want to redirect people accessing www.whateverdomain.com to the no-www version but have lots of domain, instead of writing one by one and you’re not keen in using config generator (I’m not), you can use this:
server {
listen 80;
listen [::]:80 ipv6only=on;
server_name ~^www.(?<domain>.+)$;
rewrite ^ $scheme://$domain$request_uri? permanent;
access_log /var/log/nginx/access-no_www.log;
}
Remove listen [::]:80 ipv6only=on; if you’re not using IPv6 and adjust the log file path to wherever you want (or just turn off or remove it altogether).
Note that this trick doesn’t work well with HTTPS/SSL domains since you’ll get big fat warning about incorrect domain name in certificate or about self-signed certificate if you’re using wildcard one.
Not really difficult but I guess it would be useful for some people.
First one is for nginx: create a file called `force-ssl.conf` and put in nginx’s config directory (check by `nginx -V`). And its content is:
if ($scheme = http) {
rewrite ^ https://$host$request_uri? permanent;
}
Include this file (by `include force-ssl.conf;`) in any `location … { }` block you want to force SSL on.
As for Apache, we can do it by using the usual `.htaccess` (and put in corresponding directories):
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}
The nginx rule is written by me, Apache rule is written by [someone on internet](http://joseph.randomnetworks.com/2004/07/22/redirect-to-ssl-using-apaches-htaccess/) with minor fix on skipping regex capture (`(.*)` replaced by `^`).
Many thanks to the creator himself (Igor Sysoev) for the tips.
If you find “No file specified” error message disturbing (as I did), here’s the configuration to remove it!
location ~ .php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:55555;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
Don’t use `if (-f $request_filename)` – it won’t work and if is evil. Also the `try_files` will ensure that the file actually exists – effectively disabling possible vulnerability with public file upload on certain conditions.
_Last update 2011-07-10 20:16: working version, markdown-fied_