`
gaojingsong
  • 浏览: 1182486 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
文章分类
社区版块
存档分类
最新评论

【Nginx认证配置】

阅读更多

一、Nginx的安装配置

[root@hadoop0 ~]# cd /opt/

[root@hadoop0 opt]# ls

apache-flume-1.6.0-bin           bigdata                  gitrepository           ORCLfmap        redis-3.2.0.tar.gz spark-1.3.1-bin-hadoop2.6      zookeeper-3.4.6.tar.gz    apache-flume-1.6.0-bin.tar.gz    data    

hadoop-2.7.2.tar.gz     R-3.0.1   rh            spark-1.3.1-bin-hadoop2.6.tgz

apache-flume-1.6.0-bin.tar.gz.1  elasticsearch-2.3.3      jdk1.7.0_79        R-3.0.1.tar.gz  scala-2.10.5     sqoop-1.4.6   apache-storm-0.9.6.tar.gz        elasticsearch-2.3.3.zip  kafka_2.11-0.9.0.1.tgz  

redis-3.2.0     scala-2.10.5.tgz    sqoop-1.4.6.bin__hadoop-2.0.4-alpha.tar.gz

[root@hadoop0 opt]# wget http://nginx.org/download/nginx-1.12.0.tar.gz

--2017-05-08 14:38:46--  http://nginx.org/download/nginx-1.12.0.tar.gz

Resolving nginx.org... 95.211.80.227, 206.251.255.63, 2606:7100:1:69::3f, ...

Connecting to nginx.org|95.211.80.227|:80... connected.

HTTP request sent, awaiting response... 302 Found

Location: http://211.162.74.230:9011/nginx.org/c3pr90ntc0td/download/nginx-1.12.0.tar.gz [following]

--2017-05-08 14:38:49--  http://211.162.74.230:9011/nginx.org/c3pr90ntc0td/download/nginx-1.12.0.tar.gz

Connecting to 211.162.74.230:9011... connected.

HTTP request sent, awaiting response... 200 OK

Length: 980831 (958K) [application/octet-stream]

Saving to: nginx-1.12.0.tar.gz?

 

100%[=============================>] 980,831     1.09M/s   in 0.9s    

 

2017-05-08 14:38:50 (1.09 MB/s) - 鈔ginx-1.12.0.tar.gzaved [980831/980831]

 

[root@hadoop0 opt]# ls

 nginx-1.12.0.tar.gz     redis-3.2.0.tar.gz  spark-1.3.1-bin-hadoop2.6.tgz

apache-storm-0.9.6.tar.gz 

[root@hadoop0 opt]# tar -zxvf nginx-1.12.0.tar.gz 

 

 

[root@hadoop0 opt]# cd nginx-1.12.0

[root@hadoop0 nginx-1.12.0]# ls

auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  man  README  src

[root@hadoop0 nginx-1.12.0]# ./con

conf/      configure  contrib/   

[root@hadoop0 nginx-1.12.0]# ./configure 

 

./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.

解决方案:

[root@hadoop0 nginx-1.12.0]# yum -y install pcre-devel

Total                                                                                                                                                         1.0 MB/s | 517 kB     00:00     

Running rpm_check_debug

Running Transaction Test

Transaction Test Succeeded

Running Transaction

  Updating   : pcre-7.8-7.el6.i686                                                                                                                                                        1/3 

  Installing : pcre-devel-7.8-7.el6.i686                                                                                                                                                  2/3 

  Cleanup    : pcre-7.8-6.el6.i686                                                                                                                                                        3/3 

  Verifying  : pcre-devel-7.8-7.el6.i686                                                                                                                                                  1/3 

  Verifying  : pcre-7.8-7.el6.i686                                                                                                                                                        2/3 

  Verifying  : pcre-7.8-6.el6.i686                                                                                                                                                        3/3 

 

Installed:

  pcre-devel.i686 0:7.8-7.el6                                                                                                                                                                 

 

Dependency Updated:

  pcre.i686 0:7.8-7.el6                                                                                                                                                                       

 

Complete!

 

[root@hadoop0 nginx-1.12.0]# ./configure 

creating objs/Makefile

 

Configuration summary

  + using system PCRE library

  + OpenSSL library is not used

  + using system zlib library

 

  nginx path prefix: "/usr/local/nginx"

  nginx binary file: "/usr/local/nginx/sbin/nginx"

  nginx modules path: "/usr/local/nginx/modules"

  nginx configuration prefix: "/usr/local/nginx/conf"

  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"

  nginx pid file: "/usr/local/nginx/logs/nginx.pid"

  nginx error log file: "/usr/local/nginx/logs/error.log"

  nginx http access log file: "/usr/local/nginx/logs/access.log"

  nginx http client request body temporary files: "client_body_temp"

  nginx http proxy temporary files: "proxy_temp"

  nginx http fastcgi temporary files: "fastcgi_temp"

  nginx http uwsgi temporary files: "uwsgi_temp"

  nginx http scgi temporary files: "scgi_temp"

[root@hadoop0 nginx-1.12.0]# ls 

auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  Makefile  man  objs  README  src

[root@hadoop0 nginx-1.12.0]# make 

sed -e "s|%%PREFIX%%|/usr/local/nginx|" \

                -e "s|%%PID_PATH%%|/usr/local/nginx/logs/nginx.pid|" \

                -e "s|%%CONF_PATH%%|/usr/local/nginx/conf/nginx.conf|" \

                -e "s|%%ERROR_LOG_PATH%%|/usr/local/nginx/logs/error.log|" \

                < man/nginx.8 > objs/nginx.8

make[1]: Leaving directory `/opt/nginx-1.12.0'

[root@hadoop0 nginx-1.12.0]# ls

auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  Makefile  man  objs  README  src

[root@hadoop0 nginx-1.12.0]# /usr/nginx/sbin/nginx -t 

-bash: /usr/nginx/sbin/nginx: No such file or directory

[root@hadoop0 nginx-1.12.0]# /usr/local/nginx/sbin/nginx -t 

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

[root@hadoop0 nginx-1.12.0]# ps -ef | grep nginx

root      8058  2055  0 14:45 pts/0    00:00:00 grep nginx

[root@hadoop0 nginx-1.12.0]# /usr/local/nginx/sbin/nginx 

[root@hadoop0 nginx-1.12.0]# ps -ef | grep nginx

root      8060     1  0 14:45 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx

nobody    8061  8060  0 14:45 ?        00:00:00 nginx: worker process      

root      8063  2055  0 14:45 pts/0    00:00:00 grep nginx

[root@hadoop0 nginx-1.12.0]# cd /usr/local/nginx/

[root@hadoop0 nginx]# ls

client_body_temp  conf  fastcgi_temp  html  logs  proxy_temp  sbin  scgi_temp  uwsgi_temp

[root@hadoop0 nginx]# cd conf/

[root@hadoop0 conf]# ls

fastcgi.conf          fastcgi_params          koi-utf  mime.types          nginx.conf          scgi_params          uwsgi_params          win-utf

fastcgi.conf.default  fastcgi_params.default  koi-win  mime.types.default  nginx.conf.default  scgi_params.default  uwsgi_params.default

[root@hadoop0 conf]# cat nginx.conf



 

 

二、增加用户登录认证

nginx.conf配置文件的核心如下:

server {

        listen       80;

        server_name  localhost;

 

        #charset koi8-r;

 

        #access_log  logs/host.access.log  main;

 

        location / {

            root   html;

            index  index.html index.htm;

            auth_basic "secret";

            auth_basic_user_file /usr/local/nginx/passwd.db;

        }

}

添加用户核心代码

[root@hadoop0 conf]# htpasswd -c /usr/local/nginx/passwd.db gaojs

New password: 

Re-type new password: 

Adding password for user gaojs

[root@hadoop0 conf]# /usr/local/nginx/sbin/nginx 

[root@hadoop0 conf]# cd  /usr/local/nginx/

[root@hadoop0 nginx]# ls

client_body_temp  conf  fastcgi_temp  html  logs  passwd.db  proxy_temp  sbin  scgi_temp  uwsgi_temp

[root@hadoop0 nginx]# ls -ls

total 40

4 drwx------. 2 nobody root 4096 May  8 14:44 client_body_temp

4 drwxr-xr-x. 2 root   root 4096 May  8 15:02 conf

4 drwx------. 2 nobody root 4096 May  8 14:44 fastcgi_temp

4 drwxr-xr-x. 2 root   root 4096 May  8 14:43 html

4 drwxr-xr-x. 2 root   root 4096 May  8 14:44 logs

4 -rw-r--r--. 1 root   root   20 May  8 15:02 passwd.db

4 drwx------. 2 nobody root 4096 May  8 14:44 proxy_temp

4 drwxr-xr-x. 2 root   root 4096 May  8 14:43 sbin

4 drwx------. 2 nobody root 4096 May  8 14:44 scgi_temp

4 drwx------. 2 nobody root 4096 May  8 14:44 uwsgi_temp

[root@hadoop0 nginx]# rm -rf passwd.db

[root@hadoop0 nginx]# /usr/local/nginx/sbin/nginx -s reload



 

 

附件:

[root@hadoop0 nginx]# whereis htpasswd

htpasswd: /usr/bin/htpasswd /usr/share/man/man1/htpasswd.1.gz

[root@hadoop0 nginx]# htpasswd -h 

Usage:

        htpasswd [-cmdpsD] passwordfile username

        htpasswd -b[cmdpsD] passwordfile username password

 

        htpasswd -n[mdps] username

        htpasswd -nb[mdps] username password

 -c  Create a new file.

 -n  Don't update file; display results on stdout.

 -m  Force MD5 encryption of the password.

 -d  Force CRYPT encryption of the password (default).

 -p  Do not encrypt the password (plaintext).

 -s  Force SHA encryption of the password.

 -b  Use the password from the command line rather than prompting for it.

 -D  Delete the specified user.

On Windows, NetWare and TPF systems the '-m' flag is used by default.

On all other systems, the '-p' flag will probably not work.

-c创建一个加密文件。

-n不更新加密文件,只将htpasswd命令加密后的用户名和密码显示在屏幕上。

-m默认htpassswd命令采用MD5算法对密码进行加密,该参数默认情况下可以不加。

-d表示htpassswd命令采用CRYPT算法对密码进行加密。

-s表示htpassswd命令采用SHA算法对密码进行加密。

-p表示htpassswd命令不对密码进行进行加密,即明文密码。

-b表示在htpassswd命令行中一并输入用户名和密码而不是根据提示输入密码。

-D表示删除指定的用户。

[root@hadoop0 nginx]# ls

client_body_temp  conf  fastcgi_temp  html  logs  passwd.db  proxy_temp  sbin  scgi_temp  uwsgi_temp

[root@hadoop0 nginx]# cat passwd.db 

gaojs2:Iw02ZoXegS/zI

[root@hadoop0 nginx]# 

 

  • 大小: 14 KB
  • 大小: 14.3 KB
0
1
分享到:
评论

相关推荐

    Nginx上配置Basic Authorization登录认服务证的教程

    在HTTP中,Basic Authorization基本认证是一种用来允许Web浏览器或其他客户端程序在请求时提供用户名和口令形式的身份凭证的一种登录验证方式。 在发送之前是以用户名追加一个冒号然后串接上口令,并将得出的结果...

    详解Nginx SSL快速双向认证配置(脚本)

    **Nginx SSL双向认证配置详解** 在网络安全日益重要的今天,服务器与客户端之间的通信安全成为了一个不可忽视的问题。本文将详细介绍如何在Nginx服务器上配置SSL双向认证,以提高服务器的安全性,允许只有经过验证...

    nginx集成cas登录

    目前此脚本的技术架构为nginx+lua,实现的是casclient方式,其中功能包括sso登录拦截,查询用户信息以及用户登出功能。 文章也帮助简单普及了一下cas的... nginx相关配置; 2. 熟悉lua脚本; 3. 熟悉cas的登录流程;

    Nginx双向SSL认证配置详解

    ### Nginx双向SSL认证配置详解 #### 一、引言 随着网络安全意识的提高,SSL/TLS协议在Web服务器中的应用越来越广泛。双向SSL认证不仅保护了服务器免受未授权访问,还确保了客户端的身份安全可靠。本文将详细介绍...

    linux nginx双向认证服务搭建

    #### 五、双向认证配置 为了实现更高级别的安全性,我们还需要对Nginx进行双向认证的配置: 1. **生成证书**: - 生成服务器端证书。 - 生成客户端证书。 - 为每个合法客户端分配一个唯一的数字证书。 2. **...

    MongoDB+Nginx配置

    ### MongoDB+Nginx配置详解 #### 一、概述 在现代Web开发中,高效的数据存储与灵活的内容分发网络(CDN)对于提升用户体验至关重要。MongoDB作为一种高性能、易扩展的文档型数据库,广泛应用于各类应用程序中;而...

    CentOS7 环境下Tomcat和Nginx 安全配置操作手册

    在CentOS 7环境下搭建和配置Java应用服务器,如Tomcat和Nginx,是企业IT基础设施中的常见任务。这个过程涉及到多个步骤,包括安装必要的软件、配置安全性和优化性能,确保服务稳定运行。以下是对标题和描述中所述...

    Nginx配置防盗链的完整步骤

    本篇文章将详细介绍如何在Nginx中配置防盗链。 ### 一、需求分析 通常情况下,网站所有者希望防止其他网站未经许可直接引用其服务器上的视频和图片资源,因为这可能会导致大量的流量损失,特别是对于付费的流媒体...

    Nginx用户认证配置方法详解(域名/目录)

    Nginx可以为某一个域名单独加用户认证,具体做法如下: ...2. 为Nginx添加auth认证配置 下面以某域名下面的auth目录为例,在域名的server段里加上如下代码: 代码如下:location ^~ /auth/ {location ~ .*.

    CentOS+Nginx配置详解

    【Nginx 配置详解】在 CentOS 6.5 环境下,配置 Nginx 1.6.2 可以实现多种高级功能,包括 SSL 双向认证、负载均衡和反向代理。以下是一份详细的配置步骤指南。 ### 1. 安装与准备 首先,确保你的系统是 CentOS 6.5...

    信息技术_nginx双活+双向SSL认证+高并发+安全加固+会话共享+主被动健康探测

    ### IT技术知识点详解:Nginx双活+双向SSL认证+高并发+安全加固+会话共享+主被动健康探测 #### 一、Nginx双活架构部署 双活架构意味着两个Nginx服务器同时对外提供服务,任何一方都可以独立承担业务请求,当某一方...

    docker构建nginx双向认证https服务器

    docker构建nginx双向认证https服务器。 openssl命令生成双向认证自签名证书。 nginx配置https(tls)服务。 浏览器访问服务器需要导入客户端证书到浏览器中。

    Nginx+Tomcat配置SSL双向验证示例

    本资源是一个 CentOS 下对 Nginx + Tomcat 配置 SSL 实现服务器 / 客户端双向认证配置示例。详细如何配置请参考博客《图文:CentOS 下对 Nginx + Tomcat 配置 SSL 实现服务器 / 客户端双向认证》,地址是:...

    NGINX conf 配置文件中的变量大全

    在深入探讨NGINX配置文件中的变量之前,我们先简要了解一下NGINX。NGINX是一款高性能的HTTP和反向代理服务器,广泛应用于互联网上处理高并发连接、静态文件服务以及负载均衡等场景。其配置文件是实现NGINX功能的核心...

    Nginx中配置用户服务器访问认证的方法示例

    在Nginx中配置用户服务器访问认证的方法可以分为以下几点来详细说明: 1. 生成用户认证的用户名和密码: - 使用wget命令下载一个名为htpasswd.sh的脚本文件,然后使用bash执行该脚本。 - 在执行脚本的过程中,...

    nginx替代方案,nginx代替apache与jboss

    - **简单的配置文件**:Nginx 的配置文件简洁明了,易于理解和维护。 - **成本效益**:Nginx 是一款开源软件,可以免费使用,与购买 F5 BIG-IP、NetScaler 等商业硬件负载均衡设备相比,成本大幅降低。 - **灵活的 ...

    nginx配置参数说明.txt

    基本功能: 实现与服务静态文件... 支持平滑配置更新或程序版本升级 定制访问日志,支持使用日志缓存以提高性能 支持URL rewrite 支持路径别名 支持基于IP及用户的认证: 支持速率限制,并发数限制等

Global site tag (gtag.js) - Google Analytics