10 Июля, 2016

nginx+php-fpm+vhosts

Денис Забияко
:::: nginx ::::

sudo yum install epel-release
sudo yum install nginx
sudo /etc/init.d/nginx start

chkconfig --levels 235 nginx on


ifconfig eth0 | grep inet | awk '{ print $2 }'

:::: php-fpm  :::

sudo yum install -y php-fpm php-cli php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-magickwand php-magpierss php-mbstring php-mcrypt php-mssql php-shout php-snmp php-soap php-tidy

chkconfig --levels 235 php-fpm on
service php-fpm start

:::: mysql :::

sudo yum install -y mysql mysql-server
systemctl enable mysqld.service
chkconfig --levels 235 mysqld on

mysql_secure_installation
service mysqld start

:::: vhosts :::

cd /var/www
mkdir -p linuxguru.com.ua
mkdir -p koloran.org.ua

touch /var/log/nginx/koloran.org.ua-access.log
touch /var/log/nginx/koloran.org.ua-error.log

touch /var/log/nginx/linuxguru.com.ua-access.log
touch /var/log/nginx/linuxguru.com.ua-error.log

nano /etc/nginx/conf.d/koloran.org.ua.conf

#
# The virtual server koloran.org.ua
#
server {
   listen       80;
   server_name  koloran.org.ua www.koloran.org.ua ;

  access_log /var/log/nginx/koloran.org.ua-access.log;
  error_log  /var/log/nginx/koloran.org.ua-error.log warn;

   location / {
       root  /var/www/koloran.org.ua;
       index index.php  index.html index.htm;
   }

   error_page  404              /404.html;
   location = /404.html {
       root   /usr/share/nginx/html;
   }

   error_page   500 502 503 504  /50x.html;
   location = /50x.html {
       root   /usr/share/nginx/html;
   }

   # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
   #
   location ~ .php$ {
       root           /var/www/koloran.org.ua;
       fastcgi_pass   127.0.0.1:9000;
       fastcgi_index  index.php;
       fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
       include        fastcgi_params;
   }
}

nano /etc/nginx/conf.d/linuxguru.com.ua.conf

#
# The virtual server linuxguru.com.ua
#
server {
   listen       80;
   server_name   www.linuxguru.com.ua linuxguru.com.ua;

  access_log /var/log/nginx/linuxguru.com.ua-access.log;
  error_log  /var/log/nginx/linuxguru.com.ua-error.log warn;

   location / {
       root   /var/www/linuxguru.com.ua;
       index index.php  index.html index.htm;
   }

   error_page  404              /404.html;
   location = /404.html {
       root   /usr/share/nginx/html;
   }

   error_page   500 502 503 504  /50x.html;
   location = /50x.html {
       root   /usr/share/nginx/html;
   }

   # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
   #
   location ~ .php$ {
       root           /var/www/linuxguru.com.ua;
       fastcgi_pass   127.0.0.1:9000;
       fastcgi_index  index.php;
       fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
       include        fastcgi_params;
   }
}


vim  /etc/nginx/nginx.conf
worker_processes  1;

nano /etc/nginx/nginx.conf
### add line like this on http section:
include /etc/nginx/conf.d/*.conf;

/etc/init.d/nginx restart
/etc/init.d/php-fpm restart