最近一直在研究这方面的配置,只是脚本比较复杂。在网上用力找了几天,主要教程还是那些东西。并且有点乱七八糟,小夜进行了 一些 整理。告诉你最 简单 的方法,来实现这二个方面的内容: nginx最 简单 的反向代理脚本 nginx最 简单 的前端缓存反向代理脚本
最近一直在研究这方面的配置,只是脚本比较复杂。在网上用力找了几天,主要教程还是那些东西。并且有点乱七八糟,小夜进行了一些整理。告诉你最简单的方法,来实现这二个方面的内容:
- nginx最简单的反向代理脚本
- nginx最简单的前端缓存反向代理脚本
- 只提供简单应用,自动更新等操作不讲解
- 最简单的脚本,容易学会到渣
切记:配置完成后,需要刷新nginx配置,以下2条命令都可以:
/root/lnmp reload /etc/init.d/nginx reload
一、最简单的反向代理脚本(只要修改2个网址,存成conf文件放置于vhost下):
server { listen 80; server_name www.vpsmm.com; location / { proxy_pass http://cache.vpsmm.com/; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
二、最简单的前端全缓存,反向代理脚本
#新建2个目录,放置缓存文件: mkdir /home/cache/path -p mkdir /home/cache/temp -p
修改 /usr/local/nginx/conf/nginx.conf 新增以下代码,主要是缓存相关设置,请放置于 http{ ##这里 } 中,一般加在 log_format 上面或下面均可:
client_body_buffer_size 512k; proxy_connect_timeout 5; proxy_read_timeout 60; proxy_send_timeout 5; proxy_buffer_size 16k; proxy_buffers 4 64k; proxy_busy_buffers_size 128k; proxy_temp_file_write_size 128k; proxy_temp_path /home/cache/temp; proxy_cache_path /home/cache/path levels=1:2 keys_zone=cache_one:500m inactive=7d max_size=30g; #500m是内存占用,7d是7天无访问删除,30g是缓存占具硬盘空间
以下为虚拟主机配置文件,可另存成 .conf 放置于 vhost 下面:
server { listen 80; server_name www.vpsmm.com; #主机名 location / { proxy_cache cache_one; proxy_cache_valid 200 304 3d; #正常状态缓存时间3天 proxy_cache_key $host$uri$is_args$args; proxy_pass http://cache.vpsmm.com/; #反代的网站 proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; expires 10d; #默认10天缓存 access_log /home/wwwlogs/vpsmm.log access; #日志文件 } }
点击几下网站,df -sh 命令,查看 /home/cache 目录大小,即可测试是否缓存成功。此脚本为前端全缓存,后端动态更新后,前端不会自动修改。可手动清理cache目录下文件。这个方法,可以用纯静态的形式来防CC,如果你的动态博客,受到CC攻击,可以尝试一下。
三、LNMP简单的一些防CC的办法
观看生成的.log日志文件,判断来路,直接301百度:
if ($http_referer ~* mi5.gov ) { rewrite ^(.*)$ http://www.baidu.com/ permanent; }
观看生成的.log日志文件,判断浏览器特征码,直接301百度:
if ($http_user_agent ~* firefox4.0 ) { rewrite ^(.*)$ http://www.baidu.com/ permanent; }
根据特征码,直接查找.log文件,并iptables封死相应IP:
cat com.log | grep 'Mozilla/5.0' | awk '{print "iptables -I INPUT -p tcp --dport 80 -s ", $1, "-j DROP"}'| sort -n | uniq | sh

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA


Hot AI Tools

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

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools