`
xitong
  • 浏览: 6199162 次
文章分类
社区版块
存档分类
最新评论

nginx web容器 安装与配置

 
阅读更多

1 Nginx 安装

下载地址:http://www.nginx.org/download/nginx-1.2.3.tar.gz

使用wget命令下载 # wget http://www.nginx.org/download/nginx-1.2.3.tar.gz

解压缩: # tar -zxvf nginx-1.2.3.tar.gz
设置安装目录: #./configure --prefix=/usr/local/nginx

然后系统会检查参数

我这里报了一个错:

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

看这个意思貌似缺少了PCRE library 库,那得先安装下这玩意,要是没报错可以跳过下面的步骤:

PCRE 包 下载地址:ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.20.tar.gz

同样的,下载后解压 #tar -zxvfpcre-8.20,配置 #./configure

编译#make 安装#make install

----------------------------------------------------------------------------------------------------------

OK!接着再进行nginx的安装目录: #./configure --prefix=/usr/local/nginx

又报了一个错。

./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.
缺少 zlib library 。。缺少zlib包。。这装系统的时候省事什么也不装,装个软件真没玩没了的了。。咱继续解决这问题:

下载地址:http://zlib.net/zlib-1.2.7.tar.gz 安装完这个我的就没问题了。你们的还有没有问题我就不知道了

---------------------------------------------------------------------------------------------------------------

进入nginx 的解压目录下 。。再来次 #./configure prefix=/usr/local/nginx

这下OK了吧 ~

编译: #make

安装:#make install

没出什么别的问题的话就这样安装完成了。

2 nginx配置

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

在浏览其中打开 127.0.0.1 是否显示"welcome to nginx "; 如果是的话则已经启动成功

如果没有启动成功 使用ps aux|grep nginx 查看 以及端口 netstat -ntlp|grep 80 看80端口是否已被nginx监听了

root 4962 0.0 0.0 2816 1008 ? Ss 02:00 0:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody 4966 0.0 0.1 2964 1128 ? S 02:00 0:00 nginx: worker process

注意,如果显示的不是红色的 部分/usr/local/nginx/sbin/nginx

而是别的,则需要使用kill 进程号 杀掉线程重新启动

设置开机启动:echo "/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf" >> /etc/rc.local

接着咱们来看nginx主配置文件 ( conf/nginx.conf ):

worker_processes 1;

#开启的进程数

worker_connections 1024 #每个进程最大连接数

sendfile on ; #开启搞笑文件传输模式

keepalive_timeout 100; #长链接超时时间

#########################

#########基本配置##########

server{

listen 80; #设置监听端口

server_name localhost; #设置主机名

charset utf8;#设置编码

}

location/{

root html;#指定容器文件目录

indexindex.jsp index.html ; #指定默认首页

}

error_page 500 502 503 504 /50x.html; #设置错误的默认跳转页面

location = /50x.html{

root html; #指定目录

}

############虚拟主机配置############

#第一个虚拟服务器

server{

listen 80;

server_name name1;

.……

}

#第二个虚拟服务器

server{

listen 80;

server_name name2;

.……

}

#默认虚拟服务器

server{

listen 80 default;

.……

}

#####扩展#####

#阻止访问特定目录下的文件

location ~* \.(txt|doc)$ {
root html/test;
deny all;
}

#这里的意思是阻止访问 html/test/下面的以txt 或doc 结尾的文件

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics