Install NGINX
cd /usr/ports/www/nginx && make config-recursive
make install clean
A dialog box will popup asking what modules to add when compiling nginx, check the following in addition to the defaults:
HTTP_DAV, HTTP_GZIP_STATIC, HTTP_PERL, HTTP_SSL, HTTP_DAV_EXT
On future dialog boxes, accept the defaults.
Next, run the following to install PHP5:
cd /usr/ports/lang/php5 && make install clean
A dialog box will popup, asking what options to add when compiling PHP. In addition to the defaults, select:
FPM
On future dialog boxes, accept the defaults.
Important: Select socket in process of installing the php extensions:
cd /usr/ports/lang/php55-extensions/
make config
select socket
make reinstall clean
Configuring PHP:
To configure PHP, copy the sample PHP config into production with the following command:
cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini
Next, you need to edit php.ini with this command:
ee /usr/local/etc/php.ini
Then find the following in php.ini:
- Code: Alles auswählen
output_buffering = 4096
;session.save_path = "/tmp"
upload_max_filesize = 2M
post_max_size = 8M
date.timezone = America/Los_Angeles
And set them to something along these lines:
- Code: Alles auswählen
output_buffering = OFF
session.save_path = "/tmp"
upload_max_filesize = 5120M
post_max_size = 5120M
date.timezone = America/New_York
Configuring PHP-FPM:
Next, you must edit the PHP-FPM configuration, run the following command:
ee /usr/local/etc/php-fpm.conf
Replace the default config with the following:
- Code: Alles auswählen
[global]
pid = run/php-fpm.pid
[PYDIO]
listen = /var/run/phph-fpm.socket
listen.owner = www
listen.group = www
listen.mode = 0666
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
user = www
group = www
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.max_requests = 500
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
Then you must edit the fastcgi_params file with this command:
ee /usr/local/etc/nginx/fastcgi_params
And replace the default contents of the file with this:
- Code: Alles auswählen
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_FILENAME $document_root$fastcgi_script_name;
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 HTTPS $https if_not_empty;
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;
Now you can start PHP-FPM with this command:
service php-fpm start
Configuring nginx:
To edit the nginx configuration, run the following command:
ee /usr/local/etc/nginx/nginx.conf
Then replace the default config with the following:
- Code: Alles auswählen
user www;
### Change the number of workers to the same number of cores your server has
worker_processes 2;
pid /var/run/nginx.pid;
events {
worker_connections 512;
}
http {
include mime.types;
default_type application/octet-stream;
index index.php index.htm index.html;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
# GENERAL
ignore_invalid_headers on;
sendfile off;
server_name_in_redirect off;
server_tokens off;
#SSL
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
ssl_ciphers ALL:!aNULL:!ADH:!eNULL:!LOW:!EXP:RC4+RSA:+HIGH:+MEDIUM;
ssl_prefer_server_ciphers on;
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
# TCP
tcp_nodelay off;
tcp_nopush on;
# Timeouts
client_body_timeout 65;
client_header_timeout 65;
keepalive_timeout 65 65;
send_timeout 65;
# Compression
gzip on;
gzip_buffers 256 8k;
gzip_comp_level 9;
gzip_http_version 1.0;
gzip_min_length 0;
gzip_types text/css text/javascript text/mathml text/plain text/xml application/x-javascript application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml;
gzip_vary on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
server {
root /usr/local/www;
listen 80;
server_name localhost;
location / {
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/local/www/nginx-dist;
}
# Stops the annoying error messages in the logs
location ~* ^/(favicon.ico|robots.txt) {
log_not_found off;
}
# WebDAV Rewrites
location /shares {
if (!-f $request_filename) {
rewrite ^/shares /dav.php last;
break;
}
if (!-d $request_filename) {
rewrite ^/shares /dav.php last;
break;
}
}
# Enables PHP
location ~ \.php$ {
fastcgi_pass unix:/var/run/phph-fpm.socket;
try_files $uri =404;
fastcgi_param HTTPS on;
include fastcgi_params;
}
# Enables Caching
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
expires 7d;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
}