nginx是一个高性能HTTP服务和反响代理服务,现在有很多大型网站在应用。公司的web静态服务器和代理服务器都用了nginx。nginx作为服务器高性能,配置简单,更新配置文件后,可以不彻底关闭的情况下,加载。
废话不说了,现在来安装和配置一下nginx。
安装nginx
首先去nginx官网下载 http://nginx.org/download/nginx-0.8.37.tar.gz 这是开发稳定版,有最近的功能,如果真的网站应用,建议用稳定版
除了下载nginx之外,还要下载
prce ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.02.tar.bz2 一个正则表达式的模块
zlib http://zlib.net/zlib-1.2.5.tar.gz 一个gzip的模块
下载完成后解压
shell$ sudo tar jxvf pcre-8.02.tar.bz2
shell$ sudo tar zxvf zlib-1.2.5.tar.gz
shell$ sudo tar zxvf nginx-0.8.37.tar.gz
进入 nginx-0.8.37目录
shell$ sudo ./configure --with-http_realip_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_ssl_module --with-pcre=../pcre-8.10 --with-openssl=../openssl-1.0.0 --without-http-cache --with-zlib=../zlib-1.2.5
shell$sudo make
shell$ sudo make install
安装完成,我们进入nginx的默认安装目录 /usr/local/nginx/sbin 目录,启动nginx
shell$ sudo ./nginx
然后浏览器访问http://192.168.1.101/ 安装机器地址为192.168.1.101 显示
Welcome to nginx!
安装成功了。
配置nginx
nginx的配置文件在nginx/conf/目录有一个nginx.conf文件
user nobody nobody; #用户
worker_processes 2; #线程数2
#error_log logs/error.log notice;
#pid logs/nginx.pid;
events {
use epoll; #启用epoll
worker_connections 1024; #最大链接数 82920
}
http {
server_tokens off;
include mime.types;
default_type application/octet-stream;
client_header_buffer_size 1k;
large_client_header_buffers 4 16k;
gzip on;
gzip_min_length 1100;
gzip_buffers 4 8k;
gzip_types text/plain;
output_buffers 1 32k;
postpone_output 1460;
access_log /dev/null;
#access_log /opt/logs/nginx-access.log;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 35;
server {
listen 80;
server_name www.domain.com www.domain.net;
charset gbk;
location / {
alias /opt/hosts/www/;
}
}
}
shell$ ps aux | grep nginx
root 15918 0.0 0.1 2672 616 ? Ss 21:26 0:00 nginx: master process ./nginx
nobody 15919 0.0 0.2 2832 1060 ? S 21:26 0:00 nginx: worker process
crazybao 16013 0.0 0.1 3548 812 pts/2 S+ 22:22 0:00 grep --color=auto nginx
shell$ kill -hup 15918
ok,重启成功,这样我们监听了域名 www.domain.com 和 www.domain.net两个域名的80端口,web主目录的在 /opt/hosts/www/
简单介绍到这里了,乎乎去