整合Nginx与php-fpm

1、修改nginx主配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
[[email protected] ~]# cd /etc/nginx/
[[email protected] nginx]# vim nginx.conf
#user nobody; #运行Nginx用户
worker_processes 2; #进程数,根据CPU核心来设置
#worder_cpu_affinity 4; #明确指定使用哪些CPU 如使用1、3核心: 1000 0010
worker_rlimit_nofile 51200; #设置最大系统连接数
#error_log logs/error.log; #定义错误日志文件
#error_log logs/error.log notice; #错误日志级别有:(debug|info|notice|warn|rror|crit)
#error_log logs/error.log info;
#pid logs/nginx.pid; #定义PID文件
events { #事件模块指令
use epoll; #指定事件驱动类型
worker_connections 1024; #设置每个worker进程所能处理的连接数
}
http { #Http内核模块指令
include mime.types; #加载MIME类型配置文件
default_type application/octet-stream; #设置默认的MIME类型
#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超时时间
keepalive_timeout 65;
gzipon; #启用gzip压缩
server { #定义虚拟主机
listen 80; #定义虚拟主机监听端口
server_name localhost; #定义虚拟主机名称
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /web; #定义网站目录
index index.php index.html index.htm; #定义访问默认主页文件
}
location /status{
stub_status on; #开启Nginx服务状态
access_log off; #关闭访问日志
}
location ~ \.php$ {   #以.php结尾的文件都转到172.16.14.2服务器
root /web; #php-fpm服务器上面的网站文件目录
fastcgi_pass 172.16.14.2:9000; #为php-fpm服务器IP与PORT
fastcgi_index index.php; #指定默认主页文件
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
#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 html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# HTTPS server #下面是定义Https服务器
#
#server {
# listen 443;
# server_name localhost;
# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_timeout 5m;
# ssl_protocols SSLv2 SSLv3 TLSv1;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}

2、编辑fastcgi_params参数,将里面的内容全部替换为以下内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[[email protected] nginx]# vim fastcgi_params
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
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 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;

3、创建网站存放目录并提供一个测试页面文件如:

1
2
3
[[email protected] ~]# mkdir /web
[[email protected] ~]# echo 'nginx.allen.com' > /web/index.html
[[email protected] ~]# service nginx restart #这里修改过端口所以需要重新启动

4、测试访问新建的静态测试文件

CentOS 6.4下搭建LNMP平台(下)

5、访问"status"状态页面

CentOS 6.4下搭建LNMP平台(下)

6、为php-fpm提供一个"phpinfo"页面来访问测试如下:

1
[[email protected] ~]# echo '<?php phpinfo();?>' > /web/test.php

CentOS 6.4下搭建LNMP平台(下)

7、在php-fpm服务器上面创建网站存放目录并解压phpMyAdmin然后复制到网站存放目录

1
2
3
[[email protected] ~]# tar xf phpMyAdmin-4.0.6-all-languages.tar.bz2
[[email protected] ~]# mkdir /web
[[email protected] ~]# cp -rf phpMyAdmin-4.0.6-all-languages/* /web/

8、修改phpMyAdmin配置文件,连接到Mysql数据库

1
2
3
4
5
6
7
[[email protected] ~]# cd /web
[[email protected] web]# cp config.sample.inc.php config.inc.php
######修改或添加如下行
[[email protected] web]# vim config.inc.php
$cfg['Servers'][$i]['host'] = '172.16.14.3';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'mypass';

9、在Mysql服务器上导入phpMyAdmin数据库文件

1
2
3
4
[[email protected] ~]# scp [email protected]:/web/examples/create_tables.sql ./
[email protected]'s password:
create_tables.sql 100% 7688 7.5KB/s00:00
[[email protected] ~]# mysql < create_tables.sql

10、测试在客户端访问"172.16.14.1/index.php"

CentOS 6.4下搭建LNMP平台(下)

CentOS 6.4下搭建LNMP平台(下)

至此,LNMP平台已经成功搭建完成。


本人转自:http://502245466.blog.51cto.com/7559397/1297287搭建高性能LNMP+PhpMyadmin ALLEN_YNAG 的BLOG

http://asange.blog.51cto.com/7125040/1229976Linux(6.4)+Nginx(1.4.1)+Mysql(5.6.12)+Php(5.5.0)源码编译安装 阿三哥


转载于:https://blog.51cto.com/minilinux/1308327

相关文章: