Deep learning content about Nginx
This article mainly introduces the deep learning content of Nginx, which has certain reference value. Now I share it with everyone. Friends in need can refer to it
1. Separation of dynamic and static
Separate dynamic requests and static requests through middleware.
Reason: Separate resources to reduce unnecessary request consumption and reduce request delay.
Dynamic and static request legend:
- ##Basic configuration
upstream php_api{ server 127.0.0.1:8080; } server { root filePath; location ~ \.php$ { proxy_pass http://php_api; index index.html index.htm; } location ~ \.(jpg|png|gif) { expires 1h; gzip on; } }
- URL access jump, support development and design (page jump, compatibility support, Display effect, etc.)
- SEO optimization
- Maintenance (backend maintenance, traffic forwarding, etc.)
- Security
- Configuration syntax: rewrite regex replacement [flag];
- Default: None
- Context: server, location, if
Example: rewrite ^(.*)$ /pages/main.html break;
- ##regex (regular)
- The
command in Linux can be used to test regular expressions. | Metacharacters|Meaning|
? | |
d | |
* | |
^ | |
$ | |
{n} | |
{n,} | |
[c] | |
[a-z] | |
\ | |
( ) | |
$1 | ,$2
|
break | |||||||||||||||||||||||||||
redirect | |||||||||||||||||||||||||||
permanent | |||||||||||||||||||||||||||
实例: location / { # 文件不存在,直接访问4399 if (!-f $request_filename) { rewrite ^/(.*)$ http://www.4399.com; } } Copy after login
三、Nginx的高级模块1. secure_link_module模块(1)制定并允许检查请求的链接的真实性以及保护资源免遭未经授权的访问 图例:
简单配置实例: root /opt/app/code; location / { secure_link $arg_md5,$arg_expires; secure_link_md5 "$secure_link_expires$uri 自定义字符串"; if ($secure_link = "") { return 403; } if ($secure_link = "0") { return 410; } } Copy after login 生成url的脚本: #!/bin/bash servername="你的servername" download_file="/download/test.img" time_num=$(date -d "2018-10-18 00:00:00" +%s) secure_num="自定义字符串" res=$(echo -n "${time_num}${download_file} ${secure_num}"|openssl md5 -binary | open ssl base64 | tr +/ -_ | tr -d =) echo "http://${servername}${download_file}?md5=${res}&expires=${time_num}" Copy after login 注意:1、生成脚本中自定义字符串和配置中的自定义字符串要保持一致。2、验证规则保持一致。3、如果没有openssl,可以yum安装。 2. geoip_module模块基于IP地址匹配MaxMine GeoIP二进制文件,读取IP所在地域信息。
配置示例 geoip_country /etc/nginx/geoip/GeoIP.dat; geoip_city /etc/nginx/geoip/GeoLiteCity.dat; server{ location /myip { default_type text/plain; return 200 "$remote_addr $geoip_country_name $geoip_country_code $geoip_city"; } } Copy after login 四、基于Nginx的HTTPS服务1、为什么需要HTTPS
2、HTTPS协议的实现对传输内容进行加密以及身份验证
通信原理图: 3、证书签名生成准备步骤:
生成自签证书步骤:
打包上面两个步骤生成的文件发送给签名机构即可完成证书签名
配置语法:
简单示例: server { listen 443; server_name locahost; ssl on; ssl_certificate /etc/nginx/ssl_key/ronaldo.crt; ssl_certificate_key /etc/nginx/ssl_key/ronaldo.key; index index.html index.htm; location / { root /opt/app/code; } } Copy after login 配置完成后:
4、配置苹果要求的证书
#!/bin/bash cd /opt/download wget https://www.openssl.org/source/openssl-1.0.2k.tar.gz tar zxf openssl-1.0.2k.tar.gz cd openssl-1.0.2k ./config --prefix=/usr/local/openssl make && make install mv /usr/bin/openssl /usr/bin/openssl.OFF mv /usr/include/openssl /usr/include/openssl.OFF ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl ln -s /usr/local/openssl/include/openssl /usr/include/openssl echo "/usr/local/openssl/lib" >> /etc/ld.so.conf ldconfig -v openssl version -a Copy after login
通过自签方式、符合苹果要求、通过key文件直接生成crt文件:
5、HTTPS服务优化
五、Nginx与Lua的开发Nginx+Lua优势: 1、Lua是一个简洁、轻量、可扩展的脚本语言
#!/usr/bin/lua print("Hello world") Copy after login
注意:
sum = 0 num = 1 while num <= 100 do sum = sum + num num = num + 1 end print("sum =", sum) Copy after login
sum = 0 for i = 1,100 do sum = sum + i end Copy after login
if age == 40 and sex == "Male" then print("大于40岁的男人") elseif age>60 and sex ~= "Female" then print("非女人而且大于60") else local age = io.read() print("Your age is"..age) end Copy after login 2、Nginx + Lua环境
3、Nginx调用lua模块指令Nginx的可插拔模块化加载执行,共11个处理阶段
4、Nginx Lua API
5、灰度发布按照一定的关系区别,分不分的代码进行上线,使代码的发布能平滑过渡上线。
实现灰度发布示意图: 相关推荐: The above is the detailed content of Deep learning content about Nginx. For more information, please follow other related articles on the PHP Chinese website! Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
![]() Hot AI Tools![]() Undresser.AI UndressAI-powered app for creating realistic nude photos ![]() AI Clothes RemoverOnline AI tool for removing clothes from photos. ![]() Undress AI ToolUndress images for free ![]() Clothoff.ioAI clothes remover ![]() Video Face SwapSwap faces in any video effortlessly with our completely free AI face swap tool! ![]() Hot Article
What's New in Windows 11 KB5054979 & How to Fix Update Issues
1 months ago
By DDD
How to fix KB5055523 fails to install in Windows 11?
3 weeks ago
By DDD
How to fix KB5055518 fails to install in Windows 10?
3 weeks ago
By DDD
Strength Levels for Every Enemy & Monster in R.E.P.O.
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Blue Prince: How To Get To The Basement
3 weeks ago
By DDD
![]() Hot Tools![]() Notepad++7.3.1Easy-to-use and free code editor ![]() SublimeText3 Chinese versionChinese version, very easy to use ![]() Zend Studio 13.0.1Powerful PHP integrated development environment ![]() Dreamweaver CS6Visual web development tools ![]() SublimeText3 Mac versionGod-level code editing software (SublimeText3) ![]() Hot Topics
Java Tutorial
![]() ![]()
CakePHP Tutorial
![]() ![]()
Laravel Tutorial
![]() ![]()
PHP Tutorial
![]() ![]()
C# Tutorial
![]() ![]() ![]() How to configure Nginx in Windows? Install Nginx and create a virtual host configuration. Modify the main configuration file and include the virtual host configuration. Start or reload Nginx. Test the configuration and view the website. Selectively enable SSL and configure SSL certificates. Selectively set the firewall to allow port 80 and 443 traffic. ![]() You can query the Docker container name by following the steps: List all containers (docker ps). Filter the container list (using the grep command). Gets the container name (located in the "NAMES" column). ![]() Docker container startup steps: Pull the container image: Run "docker pull [mirror name]". Create a container: Use "docker create [options] [mirror name] [commands and parameters]". Start the container: Execute "docker start [Container name or ID]". Check container status: Verify that the container is running with "docker ps". ![]() How to confirm whether Nginx is started: 1. Use the command line: systemctl status nginx (Linux/Unix), netstat -ano | findstr 80 (Windows); 2. Check whether port 80 is open; 3. Check the Nginx startup message in the system log; 4. Use third-party tools, such as Nagios, Zabbix, and Icinga. ![]() Create a container in Docker: 1. Pull the image: docker pull [mirror name] 2. Create a container: docker run [Options] [mirror name] [Command] 3. Start the container: docker start [Container name] ![]() The methods that can query the Nginx version are: use the nginx -v command; view the version directive in the nginx.conf file; open the Nginx error page and view the page title. ![]() How to configure an Nginx domain name on a cloud server: Create an A record pointing to the public IP address of the cloud server. Add virtual host blocks in the Nginx configuration file, specifying the listening port, domain name, and website root directory. Restart Nginx to apply the changes. Access the domain name test configuration. Other notes: Install the SSL certificate to enable HTTPS, ensure that the firewall allows port 80 traffic, and wait for DNS resolution to take effect. ![]() When the Nginx server goes down, you can perform the following troubleshooting steps: Check that the nginx process is running. View the error log for error messages. Check the syntax of nginx configuration. Make sure nginx has the permissions you need to access the file. Check file descriptor to open limits. Confirm that nginx is listening on the correct port. Add firewall rules to allow nginx traffic. Check reverse proxy settings, including backend server availability. For further assistance, please contact technical support. ![]() |