|
之前了解过nginx+apache前后端搭建高性能WEB服务器,照着文档做了一遍,没问题。
对apache了解不少,但nginx不怎么了解,今天抽空安装配置了一下nginx。小结:
系统环境:RHEL5.4
nginx版本:nginx-1.0.8.tar.gz
1.编译安装
./configure
make
make install
编译参数详解:
(摘自http://wiki.nginx.org/NginxChsInstallOptions)
--prefix= #指定nginx安装路径。如果不指定,默认安装到/usr/local/nginx.
--sbin-path= #指定nginx可执行文件安装路径。只能安装时指定,如果不指定,默认为/usr/local/nginx/sbin/nginx|/sbin/nginx
--conf-path= #在没有指定-c选项下默认的nginx.conf的路径。如果不指定,默认/conf/nginx.conf.
--pid-path= #在nginx.conf中没有指定pid指令时,默认的nginx.pid的路径,如果此处也没指定,默认为/logs/nginx.pid.
--lock-path= #nginx.lock文件的路径。
--error-log-path= #在nginx.conf中没有指定error_log指令时,默认的error_log路径,如果此处也没指定,默认为/logs/error.log。
--http-log-path= #在nginx.conf中没指定access_log指令时,默认的access_log路径,如果此处也未指定,默认为/logs/access.log
--user= #在nginx.conf中没指定用户时,默认的nginx用户,如果此处也未指定,默认为nobody。
--group= #在nginx.conf中没指定用户组时,默认的nginx用户组,如果此处也未指定,默认为nobody。
--builddir=DIR #指定编译的目录
--with-rtsig_module #启用rtsig模块
--with-select_module|--without-select_module #允许或不允许开启select模式,如果configure没有找到合适的模式,比如:kqueue(sun os),epoll(linux kenrel 2.6+),rtsig(实时信号)或者/dev/poll(一种类似select的模式,底层实现与select基本相同,都是采用轮询方法)SELECT模式将是默认安装模式
--with-poll_module|--without-poll_module #允许或不允许开启POLL模式,如果configure没有找到合适的模式,比如:kqueue(sun os),epoll(linux kenrel 2.6+),rtsig(实时信号)或者/dev/poll(一种类似select的模式,底层实现与select基本相同,都是采用轮询方法)POLL模式将是默认安装模式
--with-http_ssl_module #开启HTTP SSL模块,使nginx支持https请求,这个模块需要已经安装Openssl,在debian上是libssl-dev
--with-http_realip_module #启用ngx_http_realip_module
--with-http_addition_module #启用ngx_http_addition_module
--with-http_sub_module #启用--with-http_sub_module
--with-http_dav_module #启用--with-http_dav_module
--with-http_stub_status_module #启用"server status"页面
(更多参数点击:http://wiki.nginx.org/NginxChsInstallOptions)
编译示例:
用于RedHat系发行版(RHEL,CentOS,Fedora).首先安装需求包:
yum install gcc openssl-devel pcre-devel zlib-devel
配置:
./configure
--prefix=/usr \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_gzip_static_module \
--http-log-path=/var/log/nginx/access.log \
--http-client-body-temp-path=/var/tmp/nginx/client/ \
--http-proxy-temp-path=/var/tmp/nginx/proxy/ \
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/
最后编译并安装
make && make install
2.简单配置
配置文件:/usr/local/nginx/conf/nginx.conf
user nobody nobody; #使用的用户和组
worker_processes 5; #指定工作衍生进程数
pid logs/nginx.pid; #指定PID文件存放路径 #error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info; #日志存放路径及记录级别 events { use epoll; #工作模式(select(标准模式),poll(标准模式),kqueue(高效模式,适用FreeBSD 4.1+, OpenBSD 2.9+, NetBSD 2.0 and MacOS X),epoll(高效模式,本例用的。适用Linux 2.6+,SuSE 8.2,),/dev/poll(高效模式,适用Solaris 7 11/99+, HP/UX 11.22+ (eventport), IRIX 6.5.15+ 和 Tru64 UNIX 5.1A+)) worker_connections 1024; #连接数上限}http { include mime.types; #设置mime类型 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"'; log_format download '$remote_addr - $remote_user [$time_local] ' '"$request" $status $bytes_sent ' '"$http_referer" "$http_user_agent" ' '"$http_range" "$sent_http_content_range"'; #access_log logs/access.log main; #设置日志格式 keepalive_timeout 60; #设置超时时间 gzip on; #开启gzip模块,要求安装gzip 在运行./configure时要指定 #两个虚拟主机(纯静态-html 支持) server { listen 80; server_name www.asd1.com; location / { root /var/www/asd1; index asd1.html; } } server { listen 80; server_name www.asd2.com; location / { root /var/www/asd2; index asd2.html; } }}关于nginx更多点击:http://wiki.nginx.org/Main
|
|
|