HTTP Server: NGINX

Installation

by ross at 08:47:18 on August 2, 2014

Install NGINX:

# cd /usr/ports/www/nginx
# make config
Check HTTP_SSL
# make install clean

Edit /usr/local/etc/nginx/nginx.conf, set user to www and set worker_processes to the number of your cores, for example:

user www;
worker_processes 2

Inside http { } you will find commented out set of lines about log_format main - uncomment them.

Add to the same http { } section but before server { } subsection:

    # max_execution_time of php.ini:
    proxy_connect_timeout 600;
    proxy_send_timeout    600;
    proxy_read_timeout    600;
    fastcgi_read_timeout  600;
    fastcgi_send_timeout  600;

    # post_max_size and upload_max_filesize of php.ini:
    client_max_body_size 200M;

    # Enable compression
    gzip on;
    gzip_http_version 1.0;
    gzip_comp_level 6;
    gzip_min_length 0;
    gzip_buffers 16 8k;
    gzip_proxied any;
    gzip_types text/plain text/css text/xml text/javascript application/xml application/xml+rss application/javascript application/x-javascript application/json;
    gzip_disable "MSIE [1-6]\.";
    gzip_vary on;

Make the last line of http { } section to be the following:

include /usr/local/etc/nginx/sites/*.conf;

Create the directory /usr/local/etc/nginx/sites. Place your virtual hosts (aka servers) there.

Create proxy configuration: /usr/local/etc/nginx/proxy_params:

proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

Finally add to /etc/rc.conf:

# Enable nginx
nginx_enable="YES"

Edit /etc/newsyslog.conf:

/var/log/nginx-*.log    root:wheel      640  7     *    @T00  BJG /var/run/nginx.pid 30

Run:

# service newsyslog restart
# service nginx start

 

Comments