Nginx的安装与配置文件结构
内容介绍
一、LNMP架构的部署注意事项
二、Nginx的安装与配置文件结构
三、Nginx常用功能实战
一、LNMP架构的部署注意事项
1、nginx的安装过程
最常安装的有两个分别是pcre和 zlib,安装这两个的原因是为了能服务于以后,建议安装pcre,zlib,前者为了重写rewrite,后者为了gzip压缩,可以用源码方式安装,也可以用亚码方式安装。
依赖库安装如下:(最好用yum来安装)
yum-yinstall libmcrypt-develmhash-devellibxslt-devel\
libjpeglibjpeg-devellibpnglibpng-develfreetypefreetype-devellibxml2libxml2-devel\
zlibzlib-develglibcglibc-develglib2glib2-develbzip2bzip2-devel\
ncursesncurses-develcurlcurl-devele2fsprogse2fsprogs-devel \
krb5krb5-devellibidn libidn-devel openssl openssl-devel
安装nginx(0.8版)
[root@localhost nginx-1.8.1]# ./configure --with-http_status_module
--prefix=/usr/local/nginx--with-pcre=/app/lamp/pcre-8.10--with-zlib=/app/lamp/pcre-8.10—with-zlib/app/lamp/zlib-1.2.5
其中,/app/lamp/pcre-8.10和app/lamp/zlib-1.2.5为pcre和zlib源码包路径。(只需注意pcre和zlib源码包路径)
With-pcre就是将下载过来的pcre安装包指定过来,需要注意的是,之前的安装方式就是将pcre和zlib安装下来,然后编译,在nginx中安装时指定之前pcre和zlib的一个安装路径,现在只需指定pcre和zlib源码包的路径。
2、mysql安装过程(略)1、通过源码包方式安装2、mp安装
3、Php的安装过程(和LNMP基本安装过程一致)
mysql是通过yum安装的
[root@localhost/app]#tarxjvfphp-5.6.18.tar.bz2
[root@localhost/app]#tcd php-5.6.18
./configure
- prefix=/usr/ocal/php
-enable-fpm
注意:fpm是必须的一个功能点
-with-fpm-user=www-data
-with-fpm-group=www-data
-with-curl
-with-mcrypt
-enable-mbstring
-enable-pdo
-with-pdo-mysql=mysqInd
提供php与mysql相衔接的一个功能点的一个编译。
Mysql与php相关联有三种方式,
1.-with-mysql=mysqlnd直连的方式 ,最原始的方式
2.-with-mysqli=mysqlnd更新版的方式
3. -with-pdo-mysql=mysqlnd接口方式
要通过php与mysql相关联只需要一种方式
建议选这个:-with-mysqli=mysqInd
-with-mysql=mysqlnd
-with=openssl
-with-imap-ssI
-with-gd
-with-jpeg-dir=/usr/lib/
-with-png-dir=/usr/ib/
-enable-exif
-enable-zip
上面的写法中,mysql是通过yum安装的mysql来安装记得要ind
mysql是源码安装的,需修改--with-mysql=/usr/loca/mysql,
而--with-mysqli为-with-mysqli=/usr/local/mysql/bin/mysql_config
[root@localhost/app]#make
[root@localhost/app]#make install
二、nginx 的安装与配置文件结构
Nginx应用非常广泛,接触比较多,要先清楚结构,之后做配置或者相关附属工作时就比较方便。
Nginx配置文件主要分成四部分:
main(全局设置)
server(主机设置、区域主机设置)
upstream(负载均衡服务器设置)
location(URL匹配特定位置的设置)
多个server组成HTTP
如图:
最小的部分是location,多个location组成server,多个server组成一个HTTP,Main又分为两个部分,events和HTTP
三.Nginx常用功能实战
例如:conf目录(Nginx的配置文件所在目录)、html(文件存放的目录)、sbin (启动目录)、logs.
[root@localhost ~]# cd /usr/local/nginx
[root@localhost nginx]# ls
client_body_temp conf fastcgi_temp html logs proxy_temp sbin scgi_temp uwsgi_temp
[root@localhost nginx]# cd sbin/(二进制Ng的工具)
1s
[ root@localhost sbin]# ls
Nginx
[ root@localhost sbin]# 11
total 3356
- rwxr-xr-x 1 root root 3433300 Mar 9 14:58 nginx
[ root@localhost sbin]# cd logs
bash: cd: logs: NO such file or directory
[ root@localhost sbin]# ls
Nginx
[ root@localhost sbin]# cd
Ls
[ root@localhost nginx]# ls
C 1 ient_ body_ temp conf fastcgi_ temp html logs proxy_ temp sbin scgi-temp uwsgi-temp
[ root@localhost nginx]# cd logs
[ root@localhost logs]# ls
access. Log error. log host. access. log nginx.pid taob.access. log taobao. access. log
[ root@localhost logs]# 11
total 404
[root@localhost logs] #cd…
[root@localhost nginx] #1s
client body_ temp conf fastcgi temp html logs proxy_ temp sbin scgi_ temp uwsgi temp
[ root@localhost nginx]# cd conf/
[ root@localhost conf]#1s
[ root@localhost conf]#11
重点看php-fpm.conf默认的配置文件,可能会需要修改
[ root@localhost conf ]# cd
[ root@localhost nginx ]# 1s
C lient body_ temp conf fastcgi temp html logs
[ root@localhost nginx ]# cd
[ root@loca lhost local]# ls
[ root@localhost local]# cd php5.6/
I [ root@localhost php5.6]#1s
bin etc include lib php sbin var
[ root@localhost php5.6]# pwd
/usr/ local /php5.6
[ root@localhost php5.6]# cd etc/
[ root@localhost etc]# ls
pear .conf php-fpm. Conf
[ root@localhost etc]#cat php-fpm.conf |grep -v”;“
内容:
[ www]
user = www- data
group = www-data
listen = 127.0.0.1 : 9000
pm = dynami C
pm. max_ children = 5
pm. Start servers = 2
pm. min spare servers = 1
pm.max_ spare_ servers = 3
启动
[ root@localhost etc]# ls
pear. conf php- fpm. Conf
[ root@localhost etc]# cd
[ root@localhost php5.6] #1s
php fpm
I [ rootalocalhost sbin]# ./
[ root@localhost sbin]# cd . .
[ root@localhost php5.6]# ls
[ root@localhost php5.6]# cd
[ root@localhost local]# ls
[ root@localhost local ]# cd nginx
[ root@localhost nginx]# ls
[ rootalocalhost nginx]# sbin/ng inx-t
nginx: the conf iguration file /usr/ local/nginx/conf/nginx. conf syntax is ok
nginx:[warn]65536 worker connections exceed open fi le resource 1 imit : 1 02
nginx: conf iguration file /usr/ loca 1/nginx/conf /nginx.conf test is successful
user=www-data
group=www-data
listen=127.0.0.1:9000
pm=dynamic(默认模式为动态,有静态和动态的模式)pm.max_children=5(最大值)
pm.start_servers=2(刚开始启动的进程)pm.min_spare_servers=1(最小的进程数)
pm.max_spare_servers=3(最大的进程数)
查找配置文件是否正确:sbin/nginx _t
打开sb目录:cd sbin
打开fp目录:./php-fpm(父进程和子进程的关系)
打开ng目录:sbin/nginx -t
warn警告信息
