共计 7908 个字符,预计需要花费 20 分钟才能阅读完成。
CentOS 6.5 Nginx 搭建 Web 服务器,实现平滑升级,虚拟主机及访问控制。
CentOS 6.2 实战部署 Nginx+MySQL+PHP http://www.linuxidc.com/Linux/2013-09/90020.htm
使用 Nginx 搭建 WEB 服务器 http://www.linuxidc.com/Linux/2013-09/89768.htm
搭建基于 Linux6.3+Nginx1.2+PHP5+MySQL5.5 的 Web 服务器全过程 http://www.linuxidc.com/Linux/2013-09/89692.htm
CentOS 6.3 下 Nginx 性能调优 http://www.linuxidc.com/Linux/2013-09/89656.htm
CentOS 6.3 下配置 Nginx 加载 ngx_pagespeed 模块 http://www.linuxidc.com/Linux/2013-09/89657.htm
CentOS 6.4 安装配置 Nginx+Pcre+php-fpm http://www.linuxidc.com/Linux/2013-08/88984.htm
Nginx 搭建视频点播服务器(仿真专业流媒体软件)http://www.linuxidc.com/Linux/2012-08/69151.htm
一. 搭建 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 www.linuxidc.com;
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.linuxidc.com > /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.linuxidc.com www
192.168.100.1 bbs.linuxidc.com bbs
# elinks -dump http://www.linuxidc.com
www.linuxidc.com
# elinks -dump http://bbs.linuxidc.com
bbs.linuxidc.com
更多详情见请继续阅读下一页的精彩内容 :http://www.linuxidc.com/Linux/2014-05/102261p2.htm
2. 基于端口的虚拟主机
2.1 修改主配置文件
server {
listen 8080;
server_name www.linuxidc.com;
location / {
root /www;
index index.html;
}
}
server {
listen 8090;
server_name www.linuxidc.com;
location / {
root /bbs;
index index.html;
}
}
2.2 重启服务
# /usr/local/nginx/sbin/nginx -s stop
# /usr/local/nginx/sbin/nginx
2.3 客户端测试
# elinks -dump http://www.linuxidc.com:8080
www.linuxidc.com
# elinks -dump http://www.linuxidc.com:8090
bbs.linuxidc.com
3. 基于 ip 的虚拟主机
3.1 添加 IP
# ifconfig eth0:0 192.168.100.2
3.2 修改主配置文件
server {
listen 192.168.100.1:80;
# server_name www.linuxidc.com;
location / {
root /www;
index index.html;
}
}
server {
listen 192.168.100.2:80;
# server_name www.linuxidc.com;
location / {
root /bbs;
index index.html;
}
}
3.3 重启服务
# kill -HUP `cat /usr/local/nginx/logs/nginx.pid`
3.4 客户端测试
# elinks -dump 192.168.100.1
www.linuxidc.com
# elinks -dump 192.168.100.2
bbs.linuxidc.com
四、客户端访问控制
实验需求:配置基于域名的虚拟主机
www.linuxidc.com
bbs.linuxidc.com
只允许从 ip 192.168.100.254 主机访问 bbs.tarena.com 的 8080 端口, 访问时要提交正确的验证用户 admin 密码 123456 方可访问
4.1 修改主配置文件
# vim /usr/local/nginx/conf/nginx.conf
……
server {
listen 192.168.100.1:80;
server_name www.linuxidc.com;
location / {
root /www;
index index.html;
}
}
server {
listen 192.168.100.1:8080;
server_name bbs.linuxidc.com;
location / {
root /bbs;
index index.html;
allow 192.168.100.254;
deny all;
auth_basic “check your name”;
auth_basic_user_file /usr/local/nginx/conf/authuser.txt;
}
……
4.2 创建验证用户
# htpasswd -c /usr/local/nginx/conf/authuser.txt admin
New password:
Re-type new password:
Adding password for user admin
# cat /usr/local/nginx/conf/authuser.txt
admin:m37ojgyep3fls
4.3 重启服务
# kill -HUP `cat /usr/local/nginx/logs/nginx.pid`
4.4 客户端测试
Nginx 的详细介绍 :请点这里
Nginx 的下载地址 :请点这里
CentOS 6.5 Nginx 搭建 Web 服务器,实现平滑升级,虚拟主机及访问控制。
CentOS 6.2 实战部署 Nginx+MySQL+PHP http://www.linuxidc.com/Linux/2013-09/90020.htm
使用 Nginx 搭建 WEB 服务器 http://www.linuxidc.com/Linux/2013-09/89768.htm
搭建基于 Linux6.3+Nginx1.2+PHP5+MySQL5.5 的 Web 服务器全过程 http://www.linuxidc.com/Linux/2013-09/89692.htm
CentOS 6.3 下 Nginx 性能调优 http://www.linuxidc.com/Linux/2013-09/89656.htm
CentOS 6.3 下配置 Nginx 加载 ngx_pagespeed 模块 http://www.linuxidc.com/Linux/2013-09/89657.htm
CentOS 6.4 安装配置 Nginx+Pcre+php-fpm http://www.linuxidc.com/Linux/2013-08/88984.htm
Nginx 搭建视频点播服务器(仿真专业流媒体软件)http://www.linuxidc.com/Linux/2012-08/69151.htm
一. 搭建 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 www.linuxidc.com;
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.linuxidc.com > /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.linuxidc.com www
192.168.100.1 bbs.linuxidc.com bbs
# elinks -dump http://www.linuxidc.com
www.linuxidc.com
# elinks -dump http://bbs.linuxidc.com
bbs.linuxidc.com
更多详情见请继续阅读下一页的精彩内容 :http://www.linuxidc.com/Linux/2014-05/102261p2.htm