CentOS 安装 Nginx

16 篇文章 1 订阅
3 篇文章 0 订阅

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 欢迎页面即成功:

Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
...

如果启动时提示错误 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
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值