Child pages
  • Использование Nginx в качестве Web-сервера
Skip to end of metadata
Go to start of metadata



http://nginx.org/

Использование nginx позволяет ускорить загрузку статики до 40%.

Установка

  • FreeBSD 11.x

    # устанавливаем nginx из портов
    cd /usr/ports/www/nginx
    make && make install && make clean
    # проверяем
    nginx -v
    # если до этого не использовался Apache, генерируем сертификаты
    /usr/abills/misc/certs_create.sh apache
    # автозагрузка
    echo 'nginx_enable="YES"' >> /etc/rc.conf
    # устанавливаем Fast CGI wrapper
    pkg install p5-FCGI
    pkg install p5-IO-All
    pkg install fcgiwrap
    # настройки для fcgi
    echo 'fcgiwrap_enable="YES"' >> /etc/rc.conf
    echo 'fcgiwrap_user="www"' >> /etc/rc.conf
    echo 'fcgiwrap_socket_owner="www"' >> /etc/rc.conf
    
  • Ubuntu 16.04/18.04,  Debian 9

    # устанавливаем nginx, fcgi
    apt-get install fcgiwrap nginx
    # проверяем
    nginx -v
    # если до этого не использовался Apache, генерируем сертификаты
    /usr/abills/misc/certs_create.sh apache
    # автозагрузка
    update-rc.d nginx defaults
    update-rc.d fcgiwrap defaults
    
  • CentOS 7

    # устанавливаем nginx, fcgi
    yum install fcgiwrap nginx
    # проверяем
    nginx -v
    # если до этого не использовался Apache, генерируем сертификаты
    /usr/abills/misc/certs_create.sh apache
    # автозагрузка
    chkconfig nginx on
    # устанавливаем Fast CGI
    yum -y install fcgi-devel
    cd /usr/local/src/
    git clone git://github.com/gnosek/fcgiwrap.git
    cd fcgiwrap
    autoreconf -i
    ./configure
    make && make install
    yum -y install spawn-fcgi
    usermod -a -G apache nginx
    chkconfig spawn-fcgi on 

Конфигурационный файл nginx, etc

  • ВАЖНО !

    Внимательно проверьте для своей ОС следующие опции в конфигурационном файле :

    user www www;  # freebsd

    user www-data www-data; # ubuntu /debian

    user apache apache; # centos


    fastcgi_pass unix:/var/run/fcgiwrap/fcgiwrap.sock; # freebsd
    fastcgi_pass unix:/var/run/fcgiwrap.socket; # ubuntu / debian / centos


  • FreeBSD

    /usr/local/etc/nginx/nginx.conf
    user  www www;
    pid        /var/run/nginx.pid;
    worker_processes  2; # = CPU cores count
     
    events {
      worker_connections  1024;
    }
     
    http {
      include       mime.types;
      default_type  application/octet-stream;
     
      sendfile        on;
     
      keepalive_timeout  65;
     
      server {    
        listen          9443 ssl;
     
        server_name billing.abillz.net; # = DNS name or IP if no DNS record exist
        root /usr/abills/cgi-bin;
        index index.cgi;
        charset utf-8;
     
        access_log      /var/log/abills-access.log;
        error_log       /var/log/abills-error.log;
     
        ssl_certificate       /usr/abills/Certs/server.crt;
        ssl_certificate_key   /usr/abills/Certs/server.key;
     
        ssl_session_timeout  5m;
     
        ssl_protocols  SSLv2 SSLv3 TLSv1;
        ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL;
        ssl_prefer_server_ciphers   off;
     
        location / {
          try_files $uri $uri /index.cgi;
        }
        location /admin {
          try_files $uri $uri /admin/index.cgi;
        }
    
        location ^~ /images/ {
          alias /usr/abills/Abills/templates/;
          location ~* \.(jpg|gif|png|css|js|JPG|GIF)$ {
            allow all;
          }
          deny all;
        }
     
        location ~ \.cgi|pm|pl$ {
          gzip off;
          fastcgi_param HTTPS on;             
          fastcgi_pass unix:/var/run/fcgiwrap/fcgiwrap.sock;
     
          fastcgi_index index.cgi;
          fastcgi_param HTTP_CGI_AUTHORIZATION $http_authorization;
          fastcgi_param SCRIPT_FILENAME  /usr/abills/cgi-bin$fastcgi_script_name;
          include fastcgi_params;
        }
      }
    }
  • Debian / Ubuntu

    /etc/nginx/nginx.conf
    user  www-data www-data;
    pid        /var/run/nginx.pid;
    worker_processes  2; # = CPU cores count
     
    events {
      worker_connections  1024;
    }
     
    http {
      include       mime.types;
      default_type  application/octet-stream;
     
      sendfile        on;
     
      keepalive_timeout  65;
     
      server {    
        listen          9443 ssl;
     
        server_name billing.abillz.net; # = DNS name or IP if no DNS record exist
        root /usr/abills/cgi-bin;
        index index.cgi;
        charset utf-8;
     
        access_log      /var/log/abills-access.log;
        error_log       /var/log/abills-error.log;
     
        ssl_certificate       /usr/abills/Certs/server.crt;
        ssl_certificate_key   /usr/abills/Certs/server.key;
     
        ssl_session_timeout  5m;
     
        ssl_protocols  SSLv2 SSLv3 TLSv1;
        ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL;
        ssl_prefer_server_ciphers   off;
     
        location / {
          try_files $uri $uri /index.cgi;
        }
        location /admin {
          try_files $uri $uri /admin/index.cgi;
        }
    
        location ^~ /images/ {
          alias /usr/abills/Abills/templates/;
          location ~* \.(jpg|gif|png|css|js|JPG|GIF)$ {
            allow all;
          }
          deny all;
        }
     
        location ~ \.cgi|pm|pl$ {
          gzip off;
          fastcgi_param HTTPS on;             
          fastcgi_pass unix:/var/run/fcgiwrap.socket;
     
          fastcgi_index index.cgi;
          fastcgi_param HTTP_CGI_AUTHORIZATION $http_authorization;
          fastcgi_param SCRIPT_FILENAME  /usr/abills/cgi-bin$fastcgi_script_name;
          include fastcgi_params;
        }
      }
    } 
    
    
    
  • CentOS

    /etc/nginx/nginx.conf
    user  apache apache;
    pid        /var/run/nginx.pid;
    worker_processes  2; # = CPU cores count
     
    events {
      worker_connections  1024;
    }
     
    http {
      include       mime.types;
      default_type  application/octet-stream;
     
      sendfile        on;
     
      keepalive_timeout  65;
     
      server {    
        listen          9443 ssl;
     
        server_name billing.abillz.net; # = DNS name or IP if no DNS record exist
        root /usr/abills/cgi-bin;
        index index.cgi;
        charset utf-8;
     
        access_log      /var/log/abills-access.log;
        error_log       /var/log/abills-error.log;
     
        ssl_certificate       /usr/abills/Certs/server.crt;
        ssl_certificate_key   /usr/abills/Certs/server.key;
     
        ssl_session_timeout  5m;
     
        ssl_protocols  SSLv2 SSLv3 TLSv1;
        ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL;
        ssl_prefer_server_ciphers   off;
     
        location / {
          try_files $uri $uri /index.cgi;
        }
        location /admin {
          try_files $uri $uri /admin/index.cgi;
        }
    
        location ^~ /images/ {
          alias /usr/abills/Abills/templates/;
          location ~* \.(jpg|gif|png|css|js|JPG|GIF)$ {
            allow all;
          }
          deny all;
        }
     
        location ~ \.cgi|pm|pl$ {
          gzip off;
          fastcgi_param HTTPS on;             
          fastcgi_pass unix:/var/run/fcgiwrap.socket;
     
          fastcgi_index index.cgi;
          fastcgi_param HTTP_CGI_AUTHORIZATION $http_authorization;
          fastcgi_param SCRIPT_FILENAME  /usr/abills/cgi-bin$fastcgi_script_name;
          include fastcgi_params;
        }
      }
    } 
    /etc/sysconfig/spawn-fcgi
    FCGI_SOCKET=/var/run/fcgiwrap.socket
    FCGI_PROGRAM=/usr/local/sbin/fcgiwrap
    FCGI_USER=apache
    FCGI_GROUP=apache
    FCGI_EXTRA_OPTIONS="-M 0770"
    OPTIONS="-u $FCGI_USER -g $FCGI_GROUP -s $FCGI_SOCKET -S $FCGI_EXTRA_OPTIONS -F 1 -P /var/run/spawn-fcgi.pid -- $FCGI_PROGRAM"

Запускаем сервисы, проверяем :

  • No labels