


Nginx add_header instruction example analysis
Preface As we all know, the nginx configuration file sets the responseheader by using the add_header directive. Use curl to check the information of a site and find that the returned header is different from what you expected: http/2200date:thu,07feb201904:26:38gmtcontent-type:text/html;charset=utf-8vary:accept-encoding,cookiecache- control:max-age=3,must-revalidatelast-modified:thu,07feb20190
May 17, 2023 pm 06:37 PM
How Nginx dynamically forwards to upstream based on the path in the url
Scenario 1/svr1/xxxx?yyy is forwarded to svr1:8080/xxxx?yyy/svr2/xxxx?yyy and forwarded to svr2:8080/xxxx?yyy. The configuration is as follows: location~*/(srv[1-9]+)/( .*)${allowall;proxy_passhttp://$1/$2$is_args$args;proxy_set_headerhost$host;proxy_set_headerx-forwarded-for$forwarded_addr;}upstreamsrv1{serversrv1-
May 17, 2023 pm 06:28 PM
How to solve Nginx 404 error
Recently, when deploying projects, some problems occurred. As shown in the figure, the normal login interface is accessible, but after logging in, a 404 error will be reported when accessing the address. So I went to check if there were any configuration errors, but after checking, I found that nginx. The IPs and ports of the two configuration files conf and config.js are correct. This project has been deployed many times and no such errors have occurred. This is the original untouched decompressed source file of nginx.conf. The circled area is the corresponding IP and listening port that should be configured according to the project configuration. listen corresponds to the port, and server_name corresponds to the accessed IP, but this cannot be done. To solve the problem, we need to add the following sentence tr
May 17, 2023 pm 06:23 PM
nginx ip blacklist dynamic ban method
1. The solution blacklist is persisted to mysql (the common solution is redis, but it is not conducive to control, such as: different IPs set different validity periods, IP crud, statistics, etc.); through lua-nginx-module, in nginx Open up a piece of memory (lua_shared_dict), and Lua will regularly refresh the blacklist from mysql to lua_shared_dict; all requests must be checked with ipcheck in lua_shared_dict. 2. Install 2.1 install luajitcdluajit-2.0.5makemakeinstallprefix=/usr/local/
May 17, 2023 pm 05:58 PM
How to solve the pitfall of nginx configuration add_header
Preface add_header is an instruction defined in the headers module. As the name suggests, it is used to add http response headers. But please note that it is just "adding", not rewriting. So if a header already exists, problems will arise if you use add_header again. Moreover, in lower versions of nginx, add_header does not support use in error pages. This is an instruction with many pitfalls. Its processing stage is later than location processing. Although it can be written in location, if another location is rewritten, the unprocessed add_header in the previous location will be lost. For example: location
May 17, 2023 pm 05:40 PM
How to use Nginx proxy Partainer
The main purpose is to proxy the Partainer service through nginx and perform unified forwarding through nginx. 1. Start nginx. Start nginx and mount the entire nginx configuration path. The specific nginx configuration can be found in Baidu dockerrun-p80:80-namenginx--restart=always- vnginx/:/etc/nginx-dnginx modify conf.d/default.confupstreamdocker{//the name of the portainer container under the configuration path. If this nginx is not configured, noresolverdefinedtore will be used.
May 17, 2023 pm 05:04 PM
How to configure ab to do stress testing for Nginx server
ab is a performance testing tool for apache. You can only install the ab tool. Install abapt-getinstallapache2-utilscentos on ubuntu and install abyuminstallhttpd-tools. Before testing, you need to prepare a simple html, a php, and an image file. Test them separately. We put these three files in the default html directory of the nginx installation directory. After preparation, we can test ab-kc1000-n1000http://localhost/ab.html. This command will use 1000 concurrency and connect 1000 times. The result is as follows
May 17, 2023 pm 04:40 PM
How to use htpasswd to password protect the website in Nginx
The final effect is similar (the interfaces of different browsers are different): if the authentication fails, an http error will be reported: 401authorizationrequired. To implement such a function, you need to change the server configuration and set the username and password for login. First we need to change the nginx server configuration of the website. For Ubuntu server, this configuration file is usually located at /etc/nginx/sites-enabled/. For example, I use the default configuration file /etc/nginx/sites-enabled/default here. An example: copy the code as follows: server{serve
May 17, 2023 pm 03:49 PM
How to configure blacklist or whitelist function for Nginx server
1. Method of defining blacklist or whitelist: 1. Configuration format configuration keyword blacklist or whitelist file storage space white_black_list_confconf/white.listzone=white:2m;|||||||-------- ----------------------------------The storage space size here is 2m. The space size determines the capacity of the black and white list ||---- -------------------------------------------------- ----------------------------------
May 17, 2023 pm 03:40 PM
How to use Docker to mount volumes to deploy Nginx
Nginx data volume nginx has many functions, such as forward proxy, reverse proxy, load balancing, transparent proxy, etc. Generally, reverse proxy and load balancing are used more. These operations only need to modify the configuration file, so we only need to synchronize the configuration file locally. The path of the nginx configuration file is etc/nginx/nginx.conf. First create the corresponding directory and file: nginx.conf in the nginx1 directory must also be created, and the content can be left empty. Next, check whether the image is normal: If you have not downloaded the image, use the following command to pull the image (default is the latest version): dockerpullnginx Next, run the container: docker
May 17, 2023 pm 03:31 PM
How to configure nginx of Laravel Octane and WebSocket in Laradock
The previous situation describes that after LaravelOctane is installed in laradock, swoole is started. Configuring the port access connection in nginx fails, and error message 502 is reported. The configuration is as follows: location/octane{proxy_passhttp://127.0.0.1:8080;} Reason: Swoole server is in Workspace Running in a container; the Nginx server runs in an Nginx container, and you need to find the Workspace IP and configure it in nginx. Solution: dockerps checks the id of the Workspace container. dockerinspect container id, find Networ
May 17, 2023 pm 03:22 PM
How to optimize Nginx and Node.js for high-load networks
If network optimization does not first understand the underlying transmission mechanisms of nginx and node.js and carry out targeted optimization, no matter how detailed the optimization of the two is, it may be in vain. Generally, nginx connects the client and upstream applications through tcpsocket. Our system has many thresholds and restrictions for tcp, which are set through kernel parameters. The default values of these parameters are often set for general purposes and cannot meet the high traffic and short life requirements of web servers. Here are some parameters that are candidates for tuning tcp. To make them effective, you can place them in the /etc/sysctl.conf file, or put them in a new configuration file, such as /etc/sysctl.
May 17, 2023 pm 03:13 PM
How nginx realizes dynamic and static separation of tomcat
1. Why should dynamic and static separation be achieved? 1) nginx has a strong ability to process static resources. The main reason is that nginx’s efficiency in processing static pages is much higher than that of tomcat. If tomcat’s request volume is 1000 times, then nginx’s request volume is 6000 times. , tomcat's throughput per second is 0.6m, and nginx's throughput per second is 3.6m. It can be said that nginx's ability to process static resources is 6 times that of tomcat, and the advantages are evident. 2) Dynamic resources and static resources are separated to make the server structure clearer. 2. Principle of static and dynamic separation. Among the requests received by the server from the client, some are requests for static resources, such as html, css, js and image resources.
May 17, 2023 pm 02:52 PM
How to use nginx rewrite function
Preface When you browse some websites, have you ever noticed that when you enter: www.abc.com or www.abcd.com, the page can display the homepage content of www.abc.com normally. This is a usage scenario of nginxrewrite. Introduction to rewrite Rewrite is an important basic function provided by the Nginx server. Its main function is to realize URL address rewriting. The rewrite function depends on the support of pcre. Therefore, before compiling and installing the Nginx server, you need to install the pcre library (nginx uses the ngx_http_rewrite_module module to parse and handle the Rewrite function
May 17, 2023 pm 01:49 PM
Hot tools Tags

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article
Assassin's Creed Shadows: Seashell Riddle Solution
What's New in Windows 11 KB5054979 & How to Fix Update Issues
Where to find the Crane Control Keycard in Atomfall
Roblox: Dead Rails - How To Complete Every Challenge
How to fix KB5055523 fails to install in Windows 11?

Hot Tools

vc9-vc14 (32+64 bit) runtime library collection (link below)
Download the collection of runtime libraries required for phpStudy installation

VC9 32-bit
VC9 32-bit phpstudy integrated installation environment runtime library

PHP programmer toolbox full version
Programmer Toolbox v1.0 PHP Integrated Environment

VC11 32-bit
VC11 32-bit phpstudy integrated installation environment runtime library

SublimeText3 Chinese version
Chinese version, very easy to use
