nginx学习(一)

*****src目录中存放的是Nginx软件的所有源代码。之后会对其做详细的介绍。
*****man目录中存放的是Nginx软件的帮助文档。Nginx安装完成后,在linux的命令行中使用man命令可以查看
#man nginx
*****html目录和conf目录中存放的内容和Windows版本的同名目录相同。
*****auto目录存放了大量的脚本文件,和configure脚本程序有关。
*****configure文件是Nginx软件的自动脚本程序。有过Linux软件编译经验的朋友应该对configure自动脚本程序有所了解。
运行configure自动脚本一般会完成两项工作:一是检查环境,根据环境监察结果生成C代码;二是生成编译代码需要的Makefile文件。
*****CHANGES文件、LICENSE文件、README文件和Windows版本docs目录下存放的同名文件相同。
Nginx源代码的编译需要现使用configure脚本自动生成Makefile文件。configure脚本支持的常用选项




#nginx安装包
#http://nginx.org/download/
#生成Makefile文件
#./configure --prefix=/Nginx
--prefix制定了Nginx软件的安装路径,其他设置为默认设置。
后面随着功能的增加,configure选项也将逐渐增加
#编译源代码
#make
#编译顺利后,安装Nginx软件
#make install
编译完的nginx目录结构如下

安装如果失败,一般是因为缺少pcre库等问题,如果缺少,请先安装pcre之后configure指定--with-pcre=<dir>生成Makefile文件,此处的dir是解压出来的未编译的pcre目录。
PCRE 作用是让 Nginx 支持 Rewrite 功能。 1、下载 PCRE 安装包,下载地址: http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz [root@bogon src]# wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz 2、解压安装包: [root@bogon src]# tar zxvf pcre-8.35.tar.gz 3、进入安装包目录 [root@bogon src]# cd pcre-8.35 4、编译安装 [root@bogon pcre-8.35]# ./configure [root@bogon pcre-8.35]# make && make install 5、查看pcre版本 [root@bogon pcre-8.35]# pcre-config --version
重新编译安装nginx软件
首先删除上次安装的Nginx软件: #rm -rf /nginx/* 然后定位到tar包解压目录,清除上次编译的遗留文件: #make clean 之后再使用以下命令进行编译和安装: #make && make install
nginx服务器安装目录的目录结构

conf目录存放了nginx的所有配置文件。其中nginx.conf是nginx服务器的主配置文件。其他配置文件是用来配置nginx的相关功能的。比如配置fascgi使用fastcgi.conf和fastcgi_params两个文件.
html目录,index.html存放的是启动后的访问页面,50x.html是错误页面。
logs目录,是用来存放nginx服务器的日志的。目前没有启用,所以还没有日志。
sbin目录,目前只有nginx一个文件,这就是nginx服务器的主程序了。
Nginx的启停控制
1、logs下会产生一个nginx.pid的文件

[root@localhost sbin]# ./nginx -h nginx version: nginx/1.6.2 Usage: nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives] Options: -?,-h : this help 显示帮助信息 -v : show version and exit 打印版本号并退出 -V : show version and configure options then exit 打印版本号和配置并退出 -t : test configuration and exit 测试配置正确性并退出 -q : suppress non-error messages during configuration testing 测试配置是只显示错误 -s signal : send signal to a master process: stop, quit, reopen, reload 向主进程发送信号 -p prefix : set prefix path (default: /nginx//) 指定nginx服务器路径前缀 -c filename : set configuration file (default: conf/nginx.conf) 指定nginx配置文件路径 -g directives : set global directives out of configuration file 指定nginx附加配置文件路径
./nginx启动
./nginx -s stop停止
./nginx -s reopen重启
./nginx -s reload重新载入worker_processes 1; #全局生效
worker_processes 1; #全局生效
events { worker_connections 1024; #在events部分中生效 } http { #以下指令在http部分中生效 include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { #以下指令在http的server部分中生效 listen 80; server_name localhost; location / { #以下指令在http/server的localtion中生效 root html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } } ~
nginx.conf文件的基本结构
... #全局块
events { #events块
...
}
http { #http块
... #http全局块
server { #server块
... #server全局块
location [pattern] { #localtion块
...
}
location [pattern] { #localtion块
...
}
}
server { #server快
...
}
... #http全局块
}
浙公网安备 33010602011771号