CentOS安装Nginx

来源:互联网 发布:linux dd seek 编辑:程序博客网 时间:2024/04/29 13:46

Nginx (“engine x”) 是一个高性能的HTTP和反向代理服务器 , 也是一个IMAP/POP3/SMTP服务器 ; Nginx是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的 , 第一个公开版本0.1.0发布于2004年10月4日 ; 其将源代码以类 BSD 许可证的形式发布 , 因它的稳定性 , 丰富的功能集 , 示例配置文件和低系统资源的消耗而闻名 ;

CentOS 下安装 Nginx 操作如下 :

1. 下载安装包

在 http://nginx.org/en/download.html 中下载 , 如 nginx-1.11.12.tar.gz


2. 运行安装命令

# tar -zxvf nginx-1.11.12.tar.gz

# cd nginx-1.11.12

# ./configure --prefix=/usr/local/nginx

出现如下错误解决办法如下 :

./configure: error: the HTTP rewrite module requires the PCRE library.

yum -y install pcre-devel

./configure: error: the HTTP gzip module requires the zlib library.

yum install -y zlib-devel

# make

# make install   


3. 启动/关闭服务

# cd /usr/local/nginx/sbin

启动 Nginx 服务 :

# ./nginx

关闭 Nginx 服务 :

# ./nginx -s stop

检查配置文件 :

# ./nginx -t

刷新配置文件 :

# ./nginx -s reload

启动后在浏览器输入对应主机IP , 如 192.168.0.111 , 出现 Nginx 欢迎页面即成功 ;

如果启动时提示错误 nginx: [emerg] getpwnam(“www”) failed , 错误的原因是没有创建 www 这个用户 , 应该在服务器系统中添加 www 用户组和用户 www 如下命令 :

# /usr/sbin/groupadd -f www# /usr/sbin/useradd -g www www


4. 设置反向代理网址

/usr/local/nginx/conf 目录下打开 nginx.conf 文件 , 在 http 节点的 server 节点下 , 修改 location 节点 , 链接到指定的路径 , 如下 :

location / {    root   /usr/local/bin/enskblog/;    index  index.html index.htm index.shtml;}

目录 /usr/local/bin/enskblog/ 存放了我自己的静态博客文件 , 修改保存后 , 刷新下配置文件 :

# ./nginx -s reload

这时候刷新下网页 , 就可以访问到自己的静态博客了

作者 Github : tojohnonly , 博客 : EnskDeCode

0 0
原创粉丝点击