CentOS 6.4下搭建LNMP平臺(下)

整合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
[root@nginx ~]# cd /etc/nginx/
[root@nginx 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
[root@nginx 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
[root@nginx ~]# mkdir /web
[root@nginx ~]# echo 'nginx.allen.com' > /web/index.html
[root@nginx ~]# service nginx restart #這裏修改過端口所以需要重新啓動

4、測試訪問新建的靜態測試文件

231843816.gif

5、訪問"status"狀態頁面

003722898.gif

6、爲php-fpm提供一個"phpinfo"頁面來訪問測試如下:

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

001903554.gif

7、在php-fpm服務器上面創建網站存放目錄並解壓phpMyAdmin然後複製到網站存放目錄

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

8、修改phpMyAdmin配置文件,連接到Mysql數據庫

1
2
3
4
5
6
7
[root@php ~]# cd /web
[root@php web]# cp config.sample.inc.php config.inc.php
######修改或添加如下行
[root@php 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
[root@mysql ~]# scp [email protected]:/web/examples/create_tables.sql ./
[email protected]'s password:
create_tables.sql 100% 7688 7.5KB/s00:00
[root@mysql ~]# mysql < create_tables.sql

10、測試在客戶端訪問"172.16.14.1/index.php"

002739340.gif

002742137.gif

至此,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)源碼編譯安裝 阿三哥


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章