安装nginx

[root@host-172-22-14-103 ~]# yum install nginx -y

已加载插件:fastestmirror, langpacks

Loading mirror speeds from cached hostfile

 * base: mirrors.aliyun.com

 * extras: mirrors.aliyun.com

 * updates: mirrors.aliyun.com

没有可用软件包 nginx。

错误:无须任何处理

 

[root@host-172-22-14-103 ~]# cd /data/soft/

 

[root@host-172-22-14-103 soft]# wget https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-12.noarch.rpm

 

[root@host-172-22-14-103 soft]#rpm -ivh epel-release-7-12.noarch.rpm

[root@host-172-22-14-103 soft]# yum install nginx -y

[root@host-172-22-14-103 soft]# nginx -v

nginx version: nginx/1.12.2

 

systemctl start nginx.service

systemctl enable nginx.service

 

在使用nginx转发的时候,要进行一次用户身份的确认

1)通过htpasswd命令生成用户名及对应密码数据库文件。

[root@host-172-22-14-89 ~]# yum install httpd -y

[root@host-172-22-14-89 ~]# htpasswd -c /etc/nginx/passwd.db admin

New password:   888

Re-type new password:  888

Adding password for user admin

#可以看到通过htpasswd生成的密码为加密格式

[root@host-172-22-14-89 ~]# cat /etc/nginx/passwd.db 

admin:$apr1$Ijv3PMQF$1BTSrxkBxweTyi5OxSYxJ.

2)编辑虚拟主机配置文件。

[root@host-172-22-14-89 ~]# vim /etc/nginx/nginx.conf

server {

        listen 50006;

        #server_name boss.test.otosaas.com;

        location ^~ / {

                proxy_pass http://172.22.14.77:5601/;

                auth_basic "s1";

                auth_basic_user_file /etc/nginx/passwd.db;

                proxy_redirect   off;

                                                                                                                                                 

        location ^~ / {

                proxy_pass http://172.22.14.77:5601/;

                auth_basic "s1";

                auth_basic_user_file /etc/nginx/passwd.db;

                proxy_redirect   off;

                proxy_set_header Host            $host;

                proxy_set_header X-Real-Ip       $remote_addr;

                proxy_set_header X-Forwarded-for $remote_addr;

                proxy_connect_timeout 30;

                proxy_send_timeout 30;

                proxy_read_timeout 60;

                proxy_buffer_size 256k;

                proxy_buffers 4 256k;

        }

}

 

[root@i-ajelv2dj ~]# vim /etc/nginx/conf.d/consul.conf

server {

        listen 8080;

 

        #server_name boss.test.otosaas.com;

 

        location ^~ / {

                proxy_pass http://192.168.1.2:8500/;

                auth_basic "s1";

                auth_basic_user_file /etc/nginx/passwd.db;

                proxy_redirect   off;

                proxy_set_header Host            $host;

                proxy_set_header X-Real-Ip       $remote_addr;

                proxy_set_header X-Forwarded-for $remote_addr;

                proxy_connect_timeout 30;

                proxy_send_timeout 30;

                proxy_read_timeout 60;

                proxy_buffer_size 256k;

                proxy_buffers 4 256k;

        }

}

 

[root@host-172-22-14-89 ~]# service nginx restart  

你可能感兴趣的:(网关)