nginx服务器
在Linux下使用Nginx构建虚拟主机
Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器。
http://blog.s135.com/soft/linux/nginx_php/nginx/nginx-0.7.51.tar.gz
http://nchc.dl.sourceforge.net/project/pcre/pcre/8.10/pcre-8.10.tar.gz
# tar zxvf pcre-8.10.tar.gz
# cd pcre-8.10
# ./configure
# make && make install
# tar zxf nginx-0.7.51.tar.gz
# cd nginx-0.7.51
# ./configure
# make && make install
nginx安装成功后的安装目录为/usr/local/nginx
配置虚拟主机
# vi usr/local/nginx/conf/nginx.conf
在http中加上server {
listen 80;
charset utf8;
server_name www.benet.com;
root /usr/local/nginx/html;
}
server {
listen 80;
charset utf8;
server_name www.abc.com;
root /usr/local/nginx/abccom;
}
那么两个虚拟主机就配置好了。一个是www.benet.com,一个是www.abc.com。
4. 给虚拟机配置缓存,相当于 Squid 服务。
(1) 缓存不适合实时性很高的系统。
(2) 配置如下:
proxy_cache_path /usr/local/nginx/cache levels=1:2 keys_zone=STATIC:10m
inactive=24h max_size=1g;
server {
listen 80;
charset utf8;
server_name www.benet.com;
root /usr/local/nginx/html;
proxy_pass http://192.168.1.2;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host; proxy_cache STATIC; #缓存的名字 对应
上边的 keys_zone=STATIC:10m
proxy_cache_valid 200 1d;
proxy_cache_use_stale error timeout invalid_header updating
http_500 http_502 http_503 http_504;
}
}
5. 启动nginx
(1) 执行 /usr/local/nginx/sbin/nginx 即可启动nginx
6. Nginx 常用命令
(1) 启动 /usr/local/nginx/sbin/nginx
(2) 停止 /usr/local/nginx/sbin/nginx -s stop
(3)重启 /usr/local/nginx/sbin/nginx -s reload
(4)配置文件进行检查 /usr/local/nginx/sbin/nginx -t
(5) /usr/local/nginx/sbin/nginx -p 路径 ,重新设置ngix的启动目录 (default: /usr/local/nginx/)
如: /usr/local/nginx/sbin/nginx -p /home/nginx
(6) /usr/local/nginx/sbin/nginx -c filename , 重新设置配置文件 (default: conf/nginx.conf)
如: /usr/local/nginx/sbin/nginx -c /home/nginx/nginx.conf
(7) 设置开机启动服务 在/etc/rc.local文件中加入nginx启动命令,如 /usr/local/nginx/sbin/nginx
本文转自linux博客51CTO博客,原文链接http://blog.51cto.com/yangzhiming/834908如需转载请自行联系原作者
yangzhimingg