Web服務(wù)器-部署企業(yè)LNMP架構(gòu)
一、搭建Nginx服務(wù)
1、安裝支持軟件
pcre-devel
zlib-devel
gcc
gcc-c++
make
[root@www ~]# rpm -q pcre-devel zlib-devel gcc gcc-c++ make?
package pcre-devel is not installed
package zlib-devel is not installed
gcc-4.4.7-4.el6.x86_64
gcc-c++-4.4.7-4.el6.x86_64
make-3.81-20.el6.x86_64
[root@www ~]# yum -y install pcre-devel zlib-devel openssl-devel vim lrzsz wget? gcc c++ make
[root@www ~]# rpm -q pcre-devel zlib-devel gcc gcc-c++ make
pcre-devel-7.8-6.el6.x86_64
zlib-devel-1.2.3-29.el6.x86_64
gcc-4.4.7-4.el6.x86_64
gcc-c++-4.4.7-4.el6.x86_64
make-3.81-20.el6.x86_64
2、創(chuàng)建程序用戶和組
[root@www ~]# useradd -M -s /sbin/nologin nginx
[root@www ~]# tail -1 /etc/passwd ;tail -1 /etc/group
nginx:x:1000:1000::/home/nginx:/sbin/nologin
nginx:x:1000:
3、編譯安裝Nginx
[root@www ~]# tar xf nginx-1.14.2.tar.gz -C /usr/src/
[root@www ~]# cd /usr/src/nginx-1.14.2/
[root@www nginx-1.14.2]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module && make && make install……
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-file-aio --with-http_stub_status_module --with-http_gzip_static_module --with-http_flv_module --with-http_ssl_module --with-pcre && make && make install
[root@www nginx-1.14.2]# cd /usr/local/nginx/
[root@www nginx]# ls
conf? html? logs? sbin
[root@www nginx]#
[root@www nginx]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
4、編寫Nginx服務(wù)控制腳本
[root@www ~]# vim /etc/init.d/nginx
#!/bin/bash
# chkconfig: 35 90 15
# description: Nginx Server Control Script
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
case "$1" in
start)
if [ -f $PIDF ]; then
echo "Nginx is running.. Start it is error"
else
$PROG
fi
;;
stop)
if [ -f $PIDF ]; then
kill -s QUIT $(cat $PIDF)
rm -rf $PIDF
else
echo "Nginx is stopping .. Stop it is error"
fi
;;
restart)
$0 stop
$0 start
;;
reload)
if [ -f $PIDF ]; then
kill -s HUP $(cat $PIDF)
else
echo "Nginx is stopping . reload it is error"
fi
;;
status)
if [ -f $PIDF ]; then
echo "Nginx is running"
else
echo "Nginx is stopping"
fi
;;
*)
echo "Usage: $0 (start|stop|restart|reload|status)"
exit 1
esac
exit 0
5、配置Nginx服務(wù)開機(jī)自啟
[root@www ~]# echo "/usr/local/nginx/sbin/nginx" >> /etc/rc.d/rc.local
[root@www ~]# chmod +x /etc/rc.d/rc.local
[root@www ~]# nginx
[root@www ~]# netstat -anpt |grep nginx
tcp? ? ? ? 0? ? ? 0 0.0.0.0:80? ? ? ? ? ? ? ? ? 0.0.0.0:*? ? ? ? ? ? ? ? ? LISTEN? ? ? 6519/nginx
6、修改nginx.conf主配置文件,添加兩個(gè)虛擬主機(jī)
[root@www ~]# cd /usr/local/nginx/conf/
[root@www conf]# cp -p nginx.conf nginx.conf.origin
[root@www conf]# vim nginx.conf
user? nginx nginx;
worker_processes? 1;
#error_log? logs/error.log;
#error_log? logs/error.log? notice;
error_log? logs/error.log? info;
pid? ? ? ? logs/nginx.pid;
events {
? ? use epoll;
? ? worker_connections? 10240;
}
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;
? ? server {
? ? ? ? listen? ? ? 80;
? ? ? ? server_name? www.amber.com;
? ? ? ? charset utf-8;
? ? ? ? access_log? logs/www.amber.com.access.log? main;
? ? ? ? location / {
? ? ? ? ? ? root? html/www.amber.com;
? ? ? ? ? ? index? index.html index.htm;
? ? ? ? }
? ? ? ? #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;
? ? ? ? }
? ? }
? ? server {
? ? ? ? listen? ? ? 80;
? ? ? ? server_name? www.movies.com;
? ? ? ? charset utf-8;
? ? ? ? access_log? logs/www.movies.com.access.log? main;
? ? ? ? location / {
? ? ? ? ? ? root? /www.movies.com;
? ? ? ? ? ? index? index.html index.htm;
? ? ? ? }
? ? ? ? #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;
? ? ? ? }
? ? }
}
nginx配置優(yōu)化最終配置文件詳情
[root@localhost ~]# cat /usr/local/nginx/conf/nginx.conf
user? nginx;
worker_processes? 1;
#error_log? logs/error.log;
#error_log? logs/error.log? notice;
error_log? logs/error.log? info;
pid? ? ? ? logs/nginx.pid;
events {
use epoll;
? ? worker_connections? 10240;
}
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;
? ? client_header_timeout 60;
? ? client_header_buffer_size 32k;
? ? large_client_header_buffers 4 128k;
? ? client_body_timeout 60;
? ? client_max_body_size 512m;
? ? open_file_cache max=65535 inactive=20s;
? ? open_file_cache_valid 30s;
? ? open_file_cache_min_uses 1;
? ? gzip? on;
? ? gzip_static on;
? ? gzip_min_length 1k;
? ? gzip_buffers 4 16k;
? ? gzip_http_version 1.1;
? ? gzip_comp_level 2;
? ? gzip_vary on;
? ? gzip_types text/plain text/javascript application/x-javascript text/css text/xml application/xml application/xml+rss;
? ? #gzip_vary? on;
? ? fastcgi_connect_timeout 300;
? ? fastcgi_send_timeout 300;
? ? fastcgi_read_timeout 300;
? ? fastcgi_buffer_size 512k;
? ? fastcgi_buffers 6 512k;
? ? fastcgi_busy_buffers_size 512k;
? ? fastcgi_temp_file_write_size 512k;
? ? fastcgi_intercept_errors on;
? ? client_body_buffer_size 128k;
? ? proxy_connect_timeout 600;
? ? proxy_send_timeout 600;
? ? proxy_read_timeout 600;
? ? proxy_buffer_size 32k;
? ? proxy_buffers 4 32k;
? ? proxy_busy_buffers_size 54k;
? ? proxy_temp_file_write_size 2m;
? ? proxy_ignore_client_abort on;
? ? proxy_cache_path /usr/local/nginx/cache_temp levels=2:2 keys_zone=cache_temp:128m inactive=30m max_size=2g;
? ? proxy_cache_valid 200 302 10m;
? ? include /usr/local/nginx/conf/conf.d/*.conf;
}
?nginx主配置文件下include子配置文件詳情--
??也就是說(shuō)當(dāng)訪問(wèn)127.0.0.1/index.php的時(shí)候,需要讀取網(wǎng)站根目錄下面的index.php文件,如果沒(méi)有配置這一配置項(xiàng)時(shí),nginx不回去網(wǎng)站根目錄下訪問(wèn).php文件,所以返回空白
[root@localhost conf.d]# cat www.amber.conf
? ? server {
? ? ? ? listen? ? ? 80;
? ? ? ? server_name? www.amber.com;
? ? ? ? charset utf-8;
? ? ? ? access_log? logs/www.amber.com.access.log? main;
? location ~ \.(gif|jpg|jpeg|png|bmp|ico)$ {
expires 1d;
}
? ? ? ? location / {
? ? ? ? ? ? root? html/www.amber.com;
? ? ? ? ? ? index index.php 1.html? index.html index.htm;
? ? ? ? }
location ~* \.(jpg|gif|png|swf)$ {
valid_referers none blocked *.amber.com amber.com;
if ($invalid_referer) {
rewrite ^/ http://www.amber.com/error.jpg;
#return 403;
}
}
? ? ? ? #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
? ? ? ? #
? ? ? ? location ~ \.php$ {
? ? ? ? ? ? root? ? ? ? ? html;
? ? ? ? ? ? fastcgi_pass? 127.0.0.1:9000;
? ? ? ? ? ? fastcgi_index? index.php;
? ? ? ? ? ? #fastcgi_param? SCRIPT_FILENAME? /scripts$fastcgi_script_name;
? ? ? ? ? ? fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
? ? ? ? ? ? include? ? ? ? fastcgi_params;
? ? ? ? }
? ? ? ? # deny access to .htaccess files, if Apache's document root
? ? ? ? # concurs with nginx's one
? ? ? ? #
? ? ? ? #location ~ /\.ht {
? ? ? ? #? ? deny? all;
? ? ? ? #}
? ? }
七、對(duì)FPM模塊進(jìn)行參數(shù)優(yōu)化
Nginx的PHP解析功能實(shí)現(xiàn)如果是交由FPM處理的,為了提高PHP的處理速度,可對(duì)FPM模塊進(jìn)行參數(shù)調(diào)整。
FPM優(yōu)化參數(shù):
pm 使用哪種方式啟動(dòng)fpm進(jìn)程,可以說(shuō)static和dynamic,前者將產(chǎn)生 固定數(shù)量的fpm進(jìn)程,后綴將以動(dòng)態(tài)的方式產(chǎn)生fpm進(jìn)程
pm.max_children static方式下開啟的fpm進(jìn)程數(shù)
pm.start_servers 動(dòng)態(tài)方式下初始的fpm進(jìn)程數(shù)量
pm.min_spare_servers 動(dòng)態(tài)方式下最小的fpm空閑進(jìn)程數(shù)
pm.max_spare_servers 動(dòng)態(tài)方式下最大的fpm空閑進(jìn)程數(shù)
注:以上調(diào)整要根據(jù)服務(wù)器的內(nèi)存與服務(wù)器負(fù)載進(jìn)行調(diào)整
示例:
服務(wù)器為云服務(wù)器,運(yùn)行了個(gè)人論壇,內(nèi)存為1.5G,fpm進(jìn)程數(shù)為20,內(nèi)存消耗近1G,處理比較慢
# vim /usr/local/php5/etc/php-fpm.conf
優(yōu)化參數(shù)調(diào)整:
pm = dynamic
pm=start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 8
[root@www conf]# mkdir /usr/local/nginx/html/www.amber.com
[root@www conf]# mkdir /www.movies.com
[root@www conf]# chown nginx:nginx /www.movies.com/
[root@www conf]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: [warn] 10240 worker_connections exceed open file resource limit: 1024
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@www conf]# ulimit -n 65000
[root@www conf]# echo "ulimit -n 65000" >>/etc/rc.local
[root@www conf]# 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
[root@www conf]# /etc/init.d/nginx restart
7、創(chuàng)建測(cè)試頁(yè)面,進(jìn)行測(cè)試
[root@www ~]# echo "<h1>www.amber.com</h1>" >/usr/local/nginx/html/www.amber.com/index.html
[root@www ~]# echo "<h1>www.movies.com</h1>" >/www.movies.com/index.html
修改宿主機(jī)host文件:
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DSYSCONFDIR=/etc && make && make install
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -Dnetc && make && make install
二、搭建Mysql數(shù)據(jù) 庫(kù)
1、安裝支持軟件
[root@www ~]# rpm -q ncurses-devel
package ncurses-devel is not installed
[root@www ~]# yum -y install ncurses-devel
[root@www ~]# tar xf cmake-2.8.6.tar.gz -C /usr/src/
[root@www ~]# cd /usr/src/cmake-2.8.6/
[root@www cmake-2.8.6]# ./configure && gmake && gmake install
……
2、編譯安裝Mysql數(shù)據(jù)庫(kù)
[root@www cmake-2.8.6]# cd
[root@www ~]# tar xf mysql-5.5.22.tar.gz -C /usr/src/
[root@www ~]# cd /usr/src/mysql-5.5.22/
[root@www mysql-5.5.22]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -D_netc && make && make install
……
3、安裝后調(diào)整優(yōu)化
[root@www ~]# echo "PATH=$PATH:/usr/local/mysql/bin" >>/etc/profile
[root@www ~]# . /etc/profile
[root@www ~]# echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin
[root@www ~]# /bin/cp -p /usr/src/mysql-5.5.22/support-files/my-medium.cnf /etc/my.cnf
[root@www ~]# /bin/cp -p /usr/src/mysql-5.5.22/support-files/mysql.server /etc/init.d/mysqld
[root@www ~]# chmod +x /etc/init.d/mysqld
[root@www ~]# chkconfig --add mysqld
[root@www ~]# chkconfig --list mysqld
mysqld? ? ? ? 0:關(guān)閉 1:關(guān)閉 2:啟用 3:啟用 4:啟用 5:啟用 6:關(guān)閉
4、初始化數(shù)據(jù)庫(kù)
[root@www ~]# useradd -M -s /sbin/nologin mysql
[root@www ~]# chown -R mysql:mysql /usr/local/mysql/
[root@localhost ~]# vim /etc/init.d/mysqld
46 basedir=/usr/local/mysql
47 datadir=/usr/local/mysql/data
[root@www ~]# /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --user=mysql
。。。。。。
You can start the MySQL daemon with:
cd /usr/local/mysql/ ; /usr/local/mysql//bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /usr/local/mysql//mysql-test ; perl mysql-test-run.pl
Please report any problems with the /usr/local/mysql//scripts/mysqlbug script!
5、啟動(dòng)Mysql服務(wù)
[root@www ~]# /etc/init.d/mysqld start
Starting MySQL...? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? [確定]
[root@www ~]# netstat -anpt| grep mysql
tcp? ? ? ? 0? ? ? 0 0.0.0.0:3306? ? ? ? ? ? ? ? 0.0.0.0:*? ? ? ? ? ? ? ? ? LISTEN? ? ? 25190/mysqld?
6、創(chuàng)建root用戶密碼
[root@www ~]# mysqladmin -uroot password "123123";history -c
三、安裝PHP服務(wù)
1、安裝支持軟件
gd
libxml2-devel
libjpeg-devel
libpng-devel
[root@www ~]# yum -y install gd libxml2-devel libjpeg-devel libpng-devel
2、編譯安裝PHP
[root@www ~]# tar xf php-5.3.28.tar.gz -C /usr/src/
[root@www ~]# cd /usr/src/php-5.3.28/
[root@www php-5.3.28]# ./configure --prefix=/usr/local/php5 --with-gd --with-zlib --with-mysql=/usr/local/mysql/ --with-config-file-path=/usr/local/php5 --enable-mbstring --enable-fpm --with-jpeg-dir=/usr/lib? --disable-fileinfo&& make && make install
:https://blog.51cto.com/vaedit/1983603
3、安裝后優(yōu)化調(diào)整
[root@www ~]# cp -p /usr/src/php-5.3.28/php.ini-development /usr/local/php5/php.ini
[root@www ~]# ln -s /usr/local/php5/bin/* /usr/local/bin/
[root@www ~]# ln -s /usr/local/php5/sbin/* /usr/local/sbin/
4、安裝ZendGuardLoader(PHP的優(yōu)化模塊)
[root@www ~]# tar xf ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz -C /usr/src/
[root@www ~]# cp /usr/src/ZendGuardLoader-php-5.3-linux-glibc23-x86_64/php-5.3.x/ZendGuardLoader.so /usr/local/php5/lib/php/
[root@www ~]# echo -e "zend_extension=/usr/local/php5/lib/php/ZendGuardLoader.so\nzend_loader.enable=1" >> /usr/local/php5/php.ini
[root@www ~]# tail -2 /usr/local/php5/php.ini
zend_extension=/usr/local/php5/lib/php/ZendGuardLoader.so
zend_loader.enable=1
5、啟用php-fpm進(jìn)程
[root@www ~]# cd /usr/local/php5/etc/
[root@www etc]# cp -p php-fpm.conf.default php-fpm.conf
[root@www etc]# vim php-fpm.conf
25 pid = run/php-fpm.pid? //確認(rèn)pid文件位置
140 user = nginx? ? //程序用戶
141 group = nginx? ? //程序組
217 pm.max_children = 50? ? //子進(jìn)程的最大數(shù)
222 pm.start_servers = 20? ? //啟動(dòng)時(shí)開啟的進(jìn)程數(shù)
227 pm.min_spare_servers = 5? ? //最少空閑進(jìn)程數(shù)
232 pm.max_spare_servers = 35? ? //最大空閑進(jìn)程數(shù)
[root@www etc]# php-fpm
[root@www etc]# netstat -anpt |grep php-fpm
tcp? ? ? ? 0? ? ? 0 127.0.0.1:9000? ? ? ? ? ? ? 0.0.0.0:*? ? ? ? ? ? ? ? ? LISTEN? ? ? 55040/php-fpm?
6、修改/etc/init.d/nginx服務(wù)腳本
將下文腳本覆蓋原腳本:
[root@www etc]# vim /etc/init.d/nginx
#!/bin/bash
# chkconfig: 2345 99 20
# description: Nginx Server Control Script
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
PROG_FPM="/usr/local/sbin/php-fpm"
PIDF_FPM="/usr/local/php5/var/run/php-fpm.pid"
case "$1" in
? ? ? ? start)
? ? ? ? $PROG
? ? ? ? $PROG_FPM
? ? ? ? ;;
? ? ? ? stop)
? ? ? ? kill -s QUIT $(cat $PIDF)
? ? ? ? kill -s QUIT $(cat $PIDF_FPM)
? ? ? ? ;;
? ? ? ? restart)
? ? ? ? $0 stop
? ? ? ? $0 start
? ? ? ? ;;
? ? ? ? reload)
? ? ? ? kill -s HUP $(cat $PIDF)
? ? ? ? ;;
? ? ? ? *)
? ? ? ? echo "Usage: $0 (start|stop|restart|reload)"
? ? ? ? exit 1
esac
exit 0
[root@www ~]# chkconfig --del nginx
[root@www ~]# chkconfig --add nginx
[root@www ~]# /etc/init.d/nginx stop
[root@www ~]# /etc/init.d/nginx start
[root@www ~]# netstat -anpt |egrep "nginx|php-fpm"
tcp? ? ? ? 0? ? ? 0 0.0.0.0:80? ? ? ? ? ? ? ? ? 0.0.0.0:*? ? ? ? ? ? ? ? ? LISTEN? ? ? 55076/nginx? ? ? ?
tcp? ? ? ? 0? ? ? 0 127.0.0.1:9000? ? ? ? ? ? ? 0.0.0.0:*? ? ? ? ? ? ? ? ? LISTEN? ? ? 55080/php-fpm?
7、配置Nginx支持PHP解析
[root@www ~]# vim /usr/local/nginx/conf/nginx.conf
……
? ? server {
? ? ? ? listen? ? ? 80;
? ? ? ? server_name? www.movies.com;
? ? ? ? charset utf-8;
? ? ? ? access_log? logs/www.movies.com.access.log? main;
? ? ? ? location / {
? ? ? ? ? ? root? /www.movies.com;
? ? ? ? ? ? index? index.php index.html index.htm;
? ? ? ? }?
? ? ? ? location ~ \.php$ {
? ? ? ? ? ? root? /www.movies.com;
? ? ? ? ? ? fastcgi_pass? 127.0.0.1:9000;
? ? ? ? ? ? fastcgi_index? ? index.php;
? ? ? ? ? ? include? ? ? fastcgi.conf;
}?
……
[root@www ~]# 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
[root@www ~]# /etc/init.d/nginx restart
8、PHP頁(yè)面訪問(wèn)測(cè)試
[root@www ~]# vim /www.movies.com/test.php
<?php
$link=mysql_connect('localhost','root','123123');
if($link) echo "<h1>successful</h1>";
mysql_close();
? ?>
9、如果解析的PHP頁(yè)面為空白那么修改
location ~ \.php$ {
? ? ? ? ? ? root? ? ? ? ? html;
? ? ? ? ? ? fastcgi_pass? 127.0.0.1:9000;
? ? ? ? ? ? fastcgi_index? index.php;
? ? ? ? ? ? #fastcgi_param? SCRIPT_FILENAME? /scripts$fastcgi_script_name;
? ? ? ? ? ? fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;? ? ? ? ? ? include? ? ? ? fastcgi_params;
? ? ? ? }
10、如果頁(yè)面顯示的是find not file 那么 可以將fastcgi_param SCRIPT_FIL ENAME 后面的字段改為其訪問(wèn)的絕對(duì)路徑
location ~ \.php$ {
? ? ? ? ? ? root? ? ? ? ? html;
? ? ? ? ? ? fastcgi_pass? 127.0.0.1:9000;
? ? ? ? ? ? fastcgi_index? index.php;
? ? ? ? ? ? #fastcgi_param? SCRIPT_FILENAME? /scripts$fastcgi_script_name;
? ? ? ? ? ? fastcgi_param SCRIPT_FILENAME /www.movies.com/$fastcgi_script_name;
? ? ? ? ? ? include? ? ? ? fastcgi_params;
? ? ? ? }
?NGINX日志切割多虛擬機(jī)
# Created Time: Sun 03 2019年 12月 05日 星期四 14:51:252 AM UTC
#########################################################################
#!/bin/bash
# nginx日志分割
YU_NAME_ONE="www.amber.com"
YU_NAME_TWO="www.movies.com"
ACCESS_LOG_ONE="/usr/local/nginx/logs/${YU_NAME_ONE}.access.log"
ACCESS_LOG_TWO="/usr/local/nginx/logs/${YU_NAME_TWO}.access.log"
ERROR_LOG="/usr/local/nginx/logs/error.log"
NGINX="/usr/local/nginx/sbin/nginx"
DATE=`date -d "-1 day" +%Y-%m-%d`
BACKUP_DIR_ONE="/backup/logs/nginx/${YU_NAME_ONE}"
BACKUP_DIR_TWO="/backup/logs/nginx/${YU_NAME_TWO}"
STATUS=`netstat -anpt | grep :80 |wc -l`? # >1表示nginx已啟動(dòng)
[ -d ${BACKUP_DIR_ONE} ] || mkdir -p ${BACKUP_DIR_ONE} &&? [ -d ${BACKUP_DIR_TWO} ] || mkdir -p ${BACKUP_DIR_TWO}
if [ $STATUS -gt 0 ];then
? ? ? ? tar zcf ${BACKUP_DIR_ONE}/${YU_NAME_ONE}-$(date -d "-1 day" +%Y-%m-%d).tar.gz ${ACCESS_LOG_ONE}? --remove &>/dev/null
? ? ? ? tar zcf ${BACKUP_DIR_TWO}/${YU_NAME_TWO}-$(date -d "-1 day" +%Y-%m-%d).tar.gz ${
ACCESS_LOG_TWO}? --remove &>/dev/null
? ? ? ? $NGINX -s reopen
else
? ? ? ? echo "Error:? Nginx is stopped." | tee -a $ERROR_LOG
fi
11、實(shí)現(xiàn)Nginx的日志切割
#########################################################################
# File Name: nginx_cut_logs.sh
# Author: Amber
# Created Time: Sun 03 Mar 2019 02:29:22 AM UTC
#########################################################################
#!/bin/bash
# nginx日志分割
ACCESS_LOG="/usr/local/nginx/logs/access.log"
ERROR_LOG="/usr/local/nginx/logs/error.log"
NGINX="/usr/local/nginx/sbin/nginx"
DATE=`date -d "-1 day" +%Y%m%d`
BACKUP_DIR="/backup/logs/nginx/"
STATUS=`ps aux | grep "master process nginx" | wc -l` # >1表示nginx已啟動(dòng)
[ -d $BACKUP_DIR ] || mkdir -p $BACKUP_DIR
if [ $STATUS -gt 1 ];then
mv $ACCESS_LOG ${BACKUP_DIR}/access.log-$DATE
$NGINX -s reopen
gzip -9 ${BACKUP_DIR}/access.log-$DATE
else
echo "Error:? Nginx is stopped." | tee -a $ERROR_LOG
fi
find $BACKUP_DIR -name "*.log*" -mtime +30 | xargs rm -f
12、執(zhí)行.sh腳本時(shí),報(bào)錯(cuò) "start.sh? /bin/bash^M: 壞的解釋器:沒(méi)有那個(gè)文件或目錄”,因?yàn)?.sh文件是從windows拷貝過(guò)來(lái)的,所以多了\r,執(zhí)行:
13、sed -i 's/\r$//' start.sh
四、在LNMP平臺(tái),部署SKYUC應(yīng)用
1、解壓SKYUC,部署程序代碼
[root@www ~]# rpm -q unzip
unzip-6.0-1.el6.x86_64
[root@www ~]# unzip SKYUC.v3.4.2.SOURCE.zip
[root@www ~]# cd SKYUC.v3.4.2.SOURCE/
[root@www SKYUC.v3.4.2.SOURCE]# ls
Change Log.txt? Readme.txt? -??+??+?.txt? URLRewrite.txt? wwwroot
[root@www SKYUC.v3.4.2.SOURCE]# cp -rp wwwroot/ /www.movies.com/skyuc
[root@www SKYUC.v3.4.2.SOURCE]# cd /www.movies.com/skyuc/
[root@www skyuc]# chown -R nginx:nginx admincp/ data/ templates/ upload/
2、創(chuàng)建數(shù)據(jù)庫(kù)
[root@www ~]# mysql -uroot -p123123;history -c
……
mysql> create database skyucdb;
Query OK, 1 row affected (0.04 sec)
mysql> grant all on skyucdb.* to runskyuc@localhost identified by 'admin123';
Query OK, 0 rows affected (0.04 sec)
mysql> quit
Bye
3、安裝Web應(yīng)用
[root@www ~]# cd /www.movies.com/skyuc/
[root@www skyuc]# mv install/ install.bak/
[root@www skyuc]# chmod 600 install.bak/
再刷新網(wǎng)頁(yè)