nginx 笔记

1.安装

    1.linux 系统基本介绍

       linux 有多种发行版本,其中又以 redhat / debian 分别为商业版和社区版的两大代表,redhat的一个收费版为redhell,与其性能类似的免费版本是 centos,由于其免费,centos 是当前使用人数较多,较稳定的一个版本。debian 系列分为debian  和ubuntu,而ubuntu 较理想的linux 桌面版,apt 包管理相对于 redhat 的rpm。yum 是 用python 写的一个redhat系列管理器,基于RPM,更好地安装/升级/删除 软件,而当前用的较多的centos 正式属于redhat 系列,因而采用yum 进行 软件安装是比较省事的。

    2.nginx 的安装方式

  nginx 同大多数软件安装,也有两种安装方式:源码与yum安装。源码安装,一般来说,编译安装会更贴合硬件本身的特性,因而性能最优,但安装过程较为繁杂;Nginx的源码安装,默认路径为 /usr/local/nginx;

  yum 安装,则相对省事,直接下载已编译好的二进制文件,进行安装。

1.1.3  yum 安装

 根据nginx官网介绍的方法,需提供nginx 的yum 源,按照以下内容创建/etc/yum.repos.d/nginx.repo,

#官网说明:

#To set up the yum repository for RHEL/CentOS, create the file named /etc/yum.repos.d/nginx.repo with the following contents:

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/OS/OSRELEASE/$basearch/
gpgcheck=0
enabled=1

Replace “OS” with “rhel” or “centos”, depending on the distribution used, and “OSRELEASE” with “5”, “6”, or “7”, for 5.x, 6.x, or 7.x versions, respectively.

cat >  /etc/yum.repos.d/nginx.repo  << EOF   #创建该文件并进入输入模式
#/etc/yum.repos.d/nginx.repo
[nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/7/$basearch/ #替换对应的centos 版本, cat /etc/redhat-release gpgcheck=0 enabled=1
>>EOF #结束输入

cat  /etc/yum.repos.d/nginx.repo  #查看刚才修改的内容

  更改完以上yum源后,直接进行yum 安装即可

yum -y install nginx

 安装完成后,启动nginx 

centos新版本:7.0及以上:sudo systemctl start nginx  
centos(旧版本:6.8 及以下): sudo service  nginx start  

2.设置账号密码

       通过htpasswd 命令来执行创建用户密码,

  1. 首先得安装相关的htpasswd 设置软件,采用的是httpd-tools 这个工具,yum 安装

    sudo yum install -y httpd-tools
  1. 创建用户

    sudo htpasswd -c /path/.htpasswd username
    示例:sudo htpasswd -c /etc/nginx/.htpasswd nginx  
  2. 查看已创建的用户

    cat /etc/nginx/.htpasswd
  3. 更新nginx 配置

    nginx -s reload
  4. 参考资料:https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-centos-7
  5. 参考来源:https://www.digitalocean.com/community/tutorials/how-to-set-up-basic-http-authentication-with-nginx-on-centos-7
posted @ 2017-04-13 17:42  草色青青  阅读(169)  评论(0编辑  收藏  举报