* Service Nginx
Nginx developed specifically for performance optimization, which is best known advantage of its stability and low consumption of system resources, and a high processing capability HTTP concurrent connections, (single physical servers to support concurrent requests 30000-50000)
Installation and operation of operational control
1. compile and install Nginx
configuration and run Nginx needs support packages pcre, zlib, etc.
[root@centos1 ~]# yum -y install pcre-devel zlib-devel
Creating run user group
[root@centos1 ~]# useradd -M -s /sbin/nologin nginx
* Compile and install Nginx
tar zxf /mnt/nginx-1.6.2.tar.gz -C /usr/src
cd /usr/src/nginx-1.6.2
[root@centos1 nginx-1.6.2]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module
[root@centos1 nginx-1.6.2]# make&&make install
In order to run Nginx server is more convenient, you can create a link Nginx main program file for administrators and direct the implementation of "nginx" command can call the main program nginx
[root@centos1 nginx-1.6.2]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin
2.nginx operation control
* Control configuration file
to check whether the correct control file
[root@centos1 nginx-1.6.2]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
* Start, stop nginx
[root@centos1 nginx-1.6.2]# nginx
Check the nginx listen port, or accessed through a browser
[root@centos1 nginx-1.6.2]# netstat -anpt
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
3. Understand the nginx configuration file nginx.conf
Nginx main configuration file server / usr / local / nginx / conf / nginx. the conf, including global configuration, i / o Event Configuration Configuration three large and HTTP content, arranged to format statement 'key value' (which indicates the end to end) portion represents a comment to start '#'
(1) global configuration
which includes user running Nginx services, the number of work processes, error log, PID storage location, etc. Basic Settings
#user nobody; //运行用户 默认为nobody
worker_processes 1; //工作的进程数量,可以根据cpu核心总数来指定工作进程数
#error_log logs/error.log;//错误日志文件的位置
#pid logs/nginx.pid; //PID文件的位置
(2) I / O event configuration
using 'events {}' defines Nginx process tag specifies the I / O response model, connections, etc. provided for each process, and above to 2,6 kernel version recommended epoll model to improve performance; number of connections per process should be based on actual needs, generally less than 10000 (default is 1024)
events {
use epoll //使用epoll模型
worker_connections 4096;每个进程处理4096个进程连接
}
(3) HTTP Configuration
Use "http {}" tag is used to define the http server settings, including access logs, HTTP port, web directory, the default character set, the connection remains, as well as a host virtual WEB, PHP and other sites resolve global settings, where most of the configuration statements comprising defining marker "server {}" represents a specific site
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' //去掉前面的#
'$status $body_bytes_sent "$http_referer" ' //去掉前面的#
'"$http_user_agent""$http_x_forwarded_for"'; //去掉前面的#
access_log logs/access.log main; //去掉前面的#
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
4, built on the virtual domain web hosts
(1) prepare and test files web directory
[root@centos1 nginx-1.6.2]# mkdir -p /var/www/benet
[root@centos1 nginx-1.6.2]# echo "<h1>www.benet.com</h1>">/var/www/benet/index.html
[root@centos1 nginx-1.6.2]# mkdir -p /var/www/accp
[root@centos1 nginx-1.6.2]# echo "<h1>www.accp.com</h1>">/var/www/accp/index.html
(2) adjusting the configuration file nginx.conf
virtual host configuration server {} in the area, each area represents a server {} web site configuration, each designated site name, listen address, website root directory, access logs and other information, and then re loading configuration (two stage acceleration node www.accp.com www.benet.com)
server {
listen 80;
server_name www.benet.com;
charset utf-8;
access_log logs/benet.access.log main;
location / {
root /var/www/benet;
index index.html index.htm;
}
location /status {
stub_status on;
access_log off;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 80;
server_name www.accp.com;
charset utf-8;
access_log logs/accp.access.log main;
location / {
root /var/www/accp;
index index.html index.htm;
}
location /status {
stub_status on;
access_log off;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
(3 reloaded
[root@centos1 nginx-1.6.2]# killall -s QUIT nginx
[root@centos1 nginx-1.6.2]# nginx
(4) Test
Fifth, build infrastructure and application deployment LNMP
like to build as LAMP, the platform also need to build LNMP Linux server, Mysql database, PHP parsing environment, the main difference in the protocol configuration of Nginx and PHP
(1) Enable php-fpm process
[root@centos1 vod]# useradd -M -s /sbin/nologin php
① modify php-fpm.conf profiles modify the relevant parameters, and then start the process php-fpm, php-fpm monitor the machine's default port 9000
#cd /usr/local/php5/etc
#cp php-fpm.conf.default php-tpm.conf
pid = run/php-fpm.pid //确认pid文件的位置
user = php //运行用户
group = php //运行组
pm.start_servers = 20 //启动时开启的进程数
pm.min_spare_servers = 5 //最小空闲进程数
pm.max_spare_servers = 35 //最大空闲进程数
pm.max_children = 50 //最大子进程数
② start php-fpm
[root@centos1 etc]# /usr/local/sbin/php-fpm
(2) Configuration nginx: full support for php resolve
Description: Either use analytical methods need to be configured in server
[root@centos1 Desktop]# vim /usr/local/nginx/conf/nginx.conf
server {
listen 80;
server_name vod.benet.com;
charset utf-8;
access_log logs/vod.access.log main;
location / {
root /var/www/vod;
index index.html index.php;
}
location ~ \.php$ { //访问.php页面的配置段
root /var/www/vod; //php页面的根目录
fastcgi_pass 127.0.0.1:9000; //php-fpm监听地址
fastcgi_index index.php; //php首页名称
include fastcgi.conf; //fastcgi模块配置
}
}
}
[root@centos1 vod]# killall -s QUIT nginx
[root@centos1 vod]# nginx
(3) php test page views
[root@centos1 vod]# mysqladmin -u root -p password '123456'
#service mysqld start //启动数据库
mkdir /var/www/vod
在/var/www/vod下创建一个测试页面test.php
vim /var/www/vod/test.php
<?php
$link=mysqli_connect('localhost','root','123456');
if ($link) echo "<h1>恭喜你,数据库连接成功</h1>";
mysqli_close($link);
?>
then use the browser to access client
Six, LNMP application platform - network deployment sky film department
1. Download and deploy the program code
[root@centos1 ~]# unzip /mnt/SKYUC_3.4.2_for_php5.3.zip -d /usr/src
[root@centos1 ~]# cd /usr/src/SKYUC.v3.4.2.SOURCE/
[root@centos1 SKYUC.v3.4.2.SOURCE]# mv wwwroot/ /var/www/vod/skyuc
[root@centos1 SKYUC.v3.4.2.SOURCE]# cd /var/www/vod/skyuc/
[root@centos1 skyuc]# chown -R php:php admincp/ data/ templates/ upload/
2. Create a database
in order to reduce the risk of database web applications, it is recommended to provide a dedicated database and authorized user
[root@centos1 skyuc]# mysql -u root -p
mysql> create database skyucdb;
mysql> grant all on skyucdb.* to runskyuc@localhost identified by 'sky@uc123';
3. Install web application
4. Access web application system