Hi
I recently moved some of my services to another computer and used the opportunity to try using a new webserver. I have switched from lighttpd to nginx, not because lighttpd is bad - they are actually performance wise quite even, but because I have wanted to try nginx for along time(and you have to play with new stuff to learn)
I have for a long time used mozilla weave running the server part on my own server instead of using mozillas servers(again…I like to tinker with these things)
I did have a lot of trouble configuring nginx to my needs. For one it doesn’t handle php(or other fastcgi stuff) the same way as apache or lighttpd and secondly it cannot make aliases the same way as apache, so you have to do a more elaborate configuration than either apache or lighttpd
Because I couldn’t get it to work at first I didn’t use my old weave installation(which would have worked if I knew what I do now), but would try from scratch and used the weave simple server which is recommended by mozilla for people running their own server and doesn’t need clustering support and whatnot.
Ok..now to good stuff. I will not describe how to get php working with nginx. There is good documentation/blogposts covering this already. So make sure you have php working with nginx before trying out getting weave to work.
(I am using debian so some nginx configuration could be debian specific…the use a subdir called sites-available with symlinks in sites-enabled)
First unpack the weave server to something like /var/www/weave
Then create a new “server” or what is commenly known as vhost by creating a file in ex. /etc/sites-available/weave and link it into /etc/site-enabled
The content should be something like this:
server {
listen 443;
server_name weave.example.com;
root /var/www/weave;
access_log /var/log/nginx/weave.access.log;
error_log /var/log/nginx/weave.error.log;
keepalive_timeout 70;
ssl on;
ssl_certificate /etc/nginx/server.pem;
ssl_certificate_key /etc/nginx/server.pem;
ssl_protocols SSLv3 TLSv1;
ssl_ciphers HIGH:!ADH:!MD5;
location /weave {
include /etc/nginx/fastcgi_params;
fastcgi_pass localhost:8000; # port where FastCGI processes were spawned
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/weave.1mx.dk/index.php;
fastcgi_param SCRIPT_NAME /var/www/weave.1mx.dk/index.php;
if ( $request_uri ~ "/weave/([^?]*)" ) {
set $path_info /$1;
}
fastcgi_param PATH_INFO $path_info;
}
}
Here we tell it to define a new server…commenly called vhost
We tell it to listen on port 443 because I would like to use https for sending data back and forth
We give it a name it a name which the “vhost” should match
And the webroot for the vhost
The keep alive and SSL stuff is for SSL :-) Some thing I saw recommended on nginx wiki
And then the exiting part which took me long time to figure out(tried using both alias and after that rewrite to achieve my gold..to no success)…
the /location weave tell us that when a client is requesting weave.example.com/wevae which should do things stated in this block of “configuration code”
Then I include my fastcgi_params file which I have in /etc/nginx/ and use for fastcgi for this python based blog already. The contents is this:
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 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;
PHP only, required if PHP was built with –enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
This maps nginx internal variables to variable to the fastcgi process and is quite boilerplate configuration which can be found in the nginx wiki(wiki.nginx.org)
next we tell it to pass all request to the fastcgi server listening on localhost:8000 where I have my php-cgi(running fastcgi) running.
I tell that the index page should be index.php
The fastcgi_param SCRIPT_FILENAME and SCRIPT_NAME will make sure that index.php is alway the script which will be run
And now the tricky part…no rewrite and no alias we will look at the request
it says if the request is http:///weave then set $path_info to the contents of what is between the () pair. This effectively sets path_info to all things specified after http:///weave/
$path_info is the url information which is send to the php parser, so it will see all the stuff ex. http://weave.example.com/weave/this/it/will/see
The effectively the index.php will get this/it/will/see as url info and think it is called by that name, and then it does it magic with these parameters
and if we don’t access as /weave we just leave it as it is with the fastcgi_param PATH_INFO $path_info;
Then follow what is in the README in the weave simple server distribution about how to create database/create users etc. and how to configure the weave client/browserplugin to use the server
Hope this helps someone, and thanks to people which have written the nginx wiki/documentation/itself, and people who have blogged asbout nginx configuration. It has been the help I needed :-)
And maybe I am not right about how all this stuff fits together. I am still quite a nginx newbie