-
Notifications
You must be signed in to change notification settings - Fork 18
InstallNginxFreeBSD
I actually got nginx working on Debidan. See the Nginx guide for the steps used
I'm writing this document as I deploy to my FreeBSD workstation to have a local running copy. This is a work in progress, but you may find it helpful which is why I'm putting it here.
- Python 2.6 or Python 2.7 is installed (I used Python 2.7.6 for this article)
- nginx 1.2.9+ with FastCGI support and HTTP SSL support enabled (I used 1.4.4 for this article)
- fcgiwrap 1.0+ is installed
Ports:
- lang/python27
- www/nginx
- www/fcgiwrap
Run the following, which describes your profile, socket, and the number of preforks to use.
echo 'fcgiwrap_enable="YES"' >> /etc/rc.conf
echo 'fcgiwrap_flags="-c 4"' >> /etc/rc.conf
echo 'fcgiwrap_profiles="nginx"' >> /etc/rc.conf
echo 'fcgiwrap_nginx_socket="unix:/tmp/fcgiwrap.nginx.socket"' >> /etc/rc.conf
Start fcgiwrap with "/usr/local/etc/rc.d/fcgiwrap start"
Run the following
echo 'nginx_enable="YES"' >> /etc/rc.conf
Create a new nginx configuration file for your site at /usr/local/etc/nginx/rip.conf (or /etc/nginx/conf.d/rip.conf)
server {
listen 80;
server_name localhost;
root /var/www;
autoindex on;
## See http://wiki.nginx.org/Pitfalls
access_log /var/log/nginx/rip_access.log combined;
error_log /var/log/nginx/rip_error.log info;
log_not_found off;
## You may need to create /var/log/nginx
location / {
try_files $uri $uri/ @proxy;
}
location ~ (\.cgi|\.py|\.sh|\.pl|\.lua)$ {
gzip off;
root /var/www;
autoindex on;
fastcgi_pass unix:/tmp/fcgi.sock;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME /var/www/$fastcgi_script_name;
}
}
Make sure you've included rip.conf in your main nginx.conf, set your workers, and commented out the default server block.
Then start nginx with "/usr/local/etc/rc.d/nginx start" It will perform a configtest on start and you'll know quickly if you broke something.
"200 Bad Gateway" - the nginx logs shows where the problem lies.
This requires FCGI to be running. Here's a simple perl script to start fcgiwrap
on the appropriate socket (/tmp/fcgi.sock
):
#!/usr/bin/perl
use strict;
use warnings FATAL => qw( all );
use IO::Socket::UNIX;
my $bin_path = '/usr/sbin/fcgiwrap';
my $socket_path = $ARGV[0] || '/tmp/fcgi.sock';
my $num_children = $ARGV[1] || 5;
close STDIN;
unlink $socket_path;
my $socket = IO::Socket::UNIX->new(
Local => $socket_path,
Listen => 100,
);
die "Cannot create socket at $socket_path: $!\n" unless $socket;
chmod 0666, $socket_path;
for (1 .. $num_children) {
my $pid = fork;
die "Cannot fork: $!" unless defined $pid;
next if $pid;
exec $bin_path;
die "Failed to exec $bin_path: $!\n";
}
In theory all of the above should work. I got rip to come up, but unfortunately I get some errors and it's unusable. I see the following
error while contacting server:
status:200
parsererror: "SyntaxError: Unexpected token #"
I'm still troubleshooting, and will see if this is code related or configuration related once I dig further into the codebase.