第三节---nginx轻缓存安装与站点配置

1、安装轻缓存组件

下载软件包:Nginx cache purge模块(可选):http://labs.frickle.com/files/ngx_cache_purge-1.3.tar.gz

下载完成后,解压到某一目录下:tar -xzvf ngx_cache_purge-1.3.tar.gz -C /usr/local/src/software

在安装nginx时候,需要指定配置:

# ./configure \

–prefix=/usr/local/nginx-1.0.6 \  # 安装路径

–with-http_stub_status_module \ # 启用nginx状态模块

–with-http_ssl_module \ # 启用SSL模块

–with-http_realip_module \ # 启用realip模块(将用户IP转发给后端服务器)

–add-module=../ngx_cache_purge-1.3 # 添加缓存清除扩展模块

# make

# make install


站点映射

域名:www.testnginx.com 目录:/www/www.testnginx.com

修改nginx,conf配置文件

# vi nginx.conf

user  nobody nobody; # 运行nginx的所属组和所有者

worker_processes  2; # 开启两个nginx工作进程,一般几个CPU核心就写几

error_log  logs/error.log  notice; # 错误日志路径

pid        logs/nginx.pid; # pid路径

events {

worker_connections  1024; # 一个进程能同时处理1024个请求

}

http {

include       mime.types;

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”‘;

access_log  logs/access.log  main; # 默认访问日志路径

sendfile        on;

keepalive_timeout  65; # keepalive超时时间

# 开始配置一个域名,一个server配置段一般对应一个域名

server {

listen       80; #

# 在本机所有ip上监听80,也可以写为IP:80,这样的话,就只监听IP上的80口

server_name  www.testnginx.com; # 域名

root   /www/www.testnginx.com; # 站点根目录(程序目录)

index  index.html index.htm; # 索引文件

location / {  # 可以有多个location

root   /www/www.testnginx.com; # 站点根目录(程序目录)

}

error_page   500 502 503 504  /50x.html;

# 定义错误页面,如果是500错误,则把站点根目录下的50x.html返回给用户

location = /50x.html {

root   /www/www.testnginx.com;

}

}

}


Nginx启动关闭

# /usr/local/nginx/sbin/nginx  //启动nginx

# /usr/local/nginx/sbin/nginx –t //测试nginx配置文件的准确性

# /usr/local/nginx/sbin/nginx –s reload //重载nginx

# /usr/local/nginx/sbin/nginx –s stop //关闭nginx

 

测试

创建测试站点

# mkdir –p /www/www.testnginx.com

# echo “www.testnginx.com” > /www/html/www.heytool.com/index.html


启动nginx

# /usr/local/nginx/sbin/nginx –t //看到ok和successful,说明配置文件没问题

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

# /usr/local/nginx/sbin/nginx

 

绑定hosts,测试

把域名指向IP地址

IP地址     www.testnginx.com



打开www.testnginx.com,如下图:






注意,此处域名访问只能在本机才能访问成功, 如果需要外网访问,需要注册域名,进行绑定才可以访问!



详细配置请参照:http://www.docin.com/p-222277825.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值