背景:
阅读新闻
CentOS 6.5 Nginx搭建Web服务器
[日期:2014-05-25] 来源:Linux社区 作者:jinjianjun [字体:]
CentOS 6.5 Nginx搭建Web服务器,实现平滑升级,虚拟主机及访问控制。
搭建基于Linux6.3+Nginx1.2+PHP5+MySQL5.5的Web服务器全过程
CentOS 6.3下配置Nginx加载ngx_pagespeed模块
CentOS 6.4安装配置Nginx+Pcre+php-fpm
一.搭建Nginx服务器
1.释放80端口
# netstat -tulnp | grep :80
# service httpd stop
# chkconfig --level 35 httpd off
2.安装依赖软件包
# yum -y groupinstall“开发工具”“开发库”
# yum -y install gcc gcc-c++ make
# yum-y install pcre-devel
# yum -y install openssl-devel
3.安装Nginx软件
# useradd -M -s /sbin/nologin nginx //创建nginx程序用户
#tar -zxvf nginx-0.8.55.tar.gz
#cd nginx-0.8.55
./configure \
> --prefix=/usr/local/nginx \
> --user=nginx \
> --group=nginx \
> --with-http_stub_status_module \
> --with-http_ssl_module
# make && make install
4.开启服务
# cd /usr/local/nginx/sbin
# ./nginx
# echo "/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf" >> /etc/rc.local
//设置为开机启动
# netstat -tulnp | grep :80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 6924/nginx
二.平滑升级(在不停止服务的情况下,升级Nginx软件版本)
#tar -zxvf nginx-1.0.5.tar.gz //解压高版本Nginx
#cd nginx-1.0.5
./configure \
> --prefix=/usr/local/nginx \
> --user=nginx \
> --group=nginx \
> --with-http_stub_status_module \
> --with-http_ssl_module
# make
# mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old
# cp objs/nginx /usr/local/nginx/sbin/
# make upgrade
/usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
sleep 1
test -f /usr/local/nginx/logs/nginx.pid.oldbin
kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`
# /usr/local/nginx/sbin/nginx -v //查看nginx版本
nginx: nginx version: nginx/1.0.5
三.配置Nginx虚拟主机
1.
基于域名虚拟主机
1.1 编辑主配置文件
# vim /usr/local/nginx/conf/nginx.conf
……
17 http {
18 include mime.types;
19 default_type application/octet-stream;
……
34 server {
35 listen 80;
36 server_name ;
37 location / {
38 root /www;
39 index index.html;
40 }
41 }
42 server {
43 listen 80;
44 server_name bbs.linuxidc.com;
45 location / {
46 root /bbs;
47 index index.html;
48 }
1.2 制作测试网页
# mkdir /www
# mkdir /bbs
# echo > /www/index.html
# echo bbs.linuxidc.com > /bbs/index.html
1.3 检查配置文件
# ./nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
1.4 重启服务
# /usr/local/nginx/sbin/nginx -s stop
# /usr/local/nginx/sbin/nginx
1.5 客户端测试
# vim /etc/hosts
192.168.100.1 www
192.168.100.1 bbs.linuxidc.com bbs
# elinks -dump
# elinks -dump
bbs.linuxidc.com