1024programmer Nginx How Nginx allows users to access through username and password authentication

How Nginx allows users to access through username and password authentication

How does Nginx allow users to access through username and password authentication
At the end of the year, I took the time to study the ELK log analysis and monitoring system, mainly because I read the following passage and benefited a lot.
====================== Gorgeous dividing line ============= ==================
How much do you value server logs?

1. We have no logs
2. There are logs, but basically do not control the content that needs to be output
3. Frequently fine-tune the log, only output what we want to see and useful
4. Frequently monitor the log, on the one hand, help the log to fine-tune, and on the other hand, find program problems early

If you only do point 1, you can wash up and go to sleep. Many companies have achieved points 2 and 3. The server programs of these companies have basically been running for a long time, and they are relatively stable, so there is really no need to spend too much time paying attention. If a new product is launched early, I think it is necessary to achieve the fourth point.
What about the logs?

1. Having said that, we have no logs
2. Online logs tail+grep one by one
3. Write a script to download all logs within a certain time range to the local and then search

tail+grep or download the log and search it, which can cope with a few hosts and a few application deployment scenarios. But it is not suitable for multi-machine multi-application deployment. The multi-machine multi-application here means that the same application is deployed on several servers, and multiple different applications are deployed on each server. It is conceivable that in this scenario, in order to monitor or search a certain log, it is necessary to log in to multiple servers and execute multiple tail -F and grep commands. On the one hand this is very passive. On the other hand, the efficiency is very low, and after several operations, your mood will also deteriorate.

========================== Architecture Description ========= ====================
How do logstash, elasticsearch, and kibana perform nginx log analysis? First of all, in terms of architecture, nginx has log files, and the status of each of its requests is recorded in log files. Secondly, there needs to be a queue, and the list structure of redis can be used as a queue. Then analyze and query using elasticsearch.
What we need is a distributed log collection and analysis system. logstash has two roles, agent and indexer. For the agent role, it is placed on a separate web machine, and then the agent continuously reads the nginx log file, and whenever it reads new log information, it transmits the log to a redis queue on the network. For these unprocessed logs on the queue, there are several logstash indexers to receive and analyze them. After the analysis, it is stored in elasticsearch for search analysis. Then the unified kibana will display the log web interface.

Since kibaba is exposed to the Internet, in order to avoid access by illegal users, we add the Nginx server to the front end.

1. Edit the virtual host configuration file
vi logs.conf

  1. server {

  2. listen 80;

  3. server_name logs.52itstyle.com;

  4. charset utf8;

  5. location / {

  6.   proxy_pass http://127.0.0.1:5601$request_uri;

  7. proxy_set_header Host $http_host;

  8. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

  9. proxy_set_header X-Forwarded-Proto $scheme;

  10. auth_basic “secret”;

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

  12. }

  13. }


2. Generate user name and corresponding password database file through htpasswd command.
root@rhel6u3-7 server]# htpasswd -c /usr/local/nginx/passwd.db root //Create authentication information, root is the authentication user name
New password: ***** //Enter the authentication password
Re-type new password: *********** //Enter the authentication password again
Adding password for user root
[root@rhel6u3-7 server]#
[root@rhel6u3-7~]# chmod 666 /usr/local/nginx/passwd.db //Modify website authentication database permissions
[root@rhel6u3-7 ~]# chown nginx. /usr/local/nginx/passwd.db //Modify the owner and group of the website authentication database
[root@rhel6u3-7 ~]# cat /usr/local/nginx/passwd.db //You can see that the password generated by htpasswd is in encrypted format
root:ri196oC3AI48

3. Restart nginx
./nginx -s reload

4. Visit http://logs.52itstyle.com/
for the address prompt

Enter account and password to access~

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/how-nginx-allows-users-to-access-through-username-and-password-authentication/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索