Nginx: Difference between revisions
From TykWiki
Jump to navigationJump to search
| (4 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
nginx is my new favourite webserver. This page contains my notes for when I am installing it on a new machine (well, in a new jail ofcourse). | nginx is my new favourite webserver. This page contains my notes for when I am installing it on a new machine (well, in a new jail ofcourse). | ||
== | == nginx install == | ||
I generally install nginx with as few modules as possible enabled: | I generally install nginx with as few modules as possible enabled: | ||
<pre> | <pre> | ||
| Line 8: | Line 8: | ||
HTTP_MODULE=on "Enable HTTP module" | HTTP_MODULE=on "Enable HTTP module" | ||
HTTP_REWRITE_MODULE=on "Enable http_rewrite module" | HTTP_REWRITE_MODULE=on "Enable http_rewrite module" | ||
</pre> | |||
== PHP instal == | |||
I also install php-fpm by installing /usr/ports/lang/php5 with the following options: | |||
<pre> | |||
[tykling@vpnwiki /usr/ports/lang/php5]$ make showconfig | grep "=on" | |||
FPM=on "Build FPM version (experimental)" | |||
SUHOSIN=on "Enable Suhosin protection system" | |||
IPV6=on "Enable ipv6 support" | |||
</pre> | </pre> | ||
| Line 38: | Line 47: | ||
I also create the folder <code>/var/php/</code> to hold the actual socket opened by php-fpm. | I also create the folder <code>/var/php/</code> to hold the actual socket opened by php-fpm. | ||
== | == nginx config == | ||
After installing nginx I replace the default config with something more sensible, like this example for a mediawiki install: | After installing nginx I replace the default config with something more sensible, like this example for a mediawiki install: | ||
| Line 68: | Line 77: | ||
client_body_timeout 60; | client_body_timeout 60; | ||
#mediawiki specific config | |||
location / { | location / { | ||
try_files $uri $uri/ @rewrite; | try_files $uri $uri/ @rewrite; | ||
| Line 109: | Line 118: | ||
} | } | ||
} | } | ||
</pre> | |||
== Enable stuff in rc.conf == | |||
<pre> | |||
#webserver | |||
nginx_enable="YES" | |||
php_fpm_enable="YES" | |||
</pre> | </pre> | ||
Latest revision as of 23:09, 14 January 2012
nginx is my new favourite webserver. This page contains my notes for when I am installing it on a new machine (well, in a new jail ofcourse).
nginx install
I generally install nginx with as few modules as possible enabled:
[tykling@vpnwiki /usr/ports/www/nginx]$ make showconfig | grep "=on"
IPV6=on "Enable IPv6"
HTTP_MODULE=on "Enable HTTP module"
HTTP_REWRITE_MODULE=on "Enable http_rewrite module"
PHP instal
I also install php-fpm by installing /usr/ports/lang/php5 with the following options:
[tykling@vpnwiki /usr/ports/lang/php5]$ make showconfig | grep "=on"
FPM=on "Build FPM version (experimental)"
SUHOSIN=on "Enable Suhosin protection system"
IPV6=on "Enable ipv6 support"
Misc
Create logfiles folder
I like to keep my webserver logs in /usr/local/www/logs/ so that folder needs to be created:
sudo mkdir /usr/local/www/logs
php-fpm config
I use php-fpm instead of fastcgi to handle the PHP scripts. The config I use for php-fpm is below:
$ cat /usr/local/etc/php-fpm.conf [global] pid = run/php-fpm.pid log_level = error [www] listen = /var/php/php-fpm.socket user = www group = www pm = dynamic pm.max_children = 50 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35
I also create the folder /var/php/ to hold the actual socket opened by php-fpm.
nginx config
After installing nginx I replace the default config with something more sensible, like this example for a mediawiki install:
worker_processes 1;
error_log /usr/local/www/logs/error.log;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type text/plain;
log_format main '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_forwarded_for"';
error_log /usr/local/www/logs/vpnwiki.ryst.cn.dom.error.log;
sendfile off;
keepalive_timeout 65;
server {
listen 80 default_server;
listen [::]:80 default_server;
access_log /usr/local/www/logs/vpnwiki.ryst.cn.dom.access.log main;
server_name wiki.tyk.nu;
root /usr/local/www/mediawiki;
client_max_body_size 5m;
client_body_timeout 60;
#mediawiki specific config
location / {
try_files $uri $uri/ @rewrite;
index index.php;
}
location @rewrite {
rewrite ^/(.*)$ /index.php?title=$1&$args;
}
location ^~ /maintenance/ {
return 403;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/var/php/php-fpm.socket;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
try_files $uri /index.php;
expires max;
log_not_found off;
}
location = /_.gif {
expires max;
empty_gif;
}
location ^~ /cache/ {
deny all;
}
location /dumps {
root /usr/local/www/mediawiki/local;
autoindex on;
}
}
}
Enable stuff in rc.conf
#webserver nginx_enable="YES" php_fpm_enable="YES"