Virtual host IP configuration, nginx.conf file configuration and log file cutting

Source: Internet
Author: User

Today, a rough collation of the virtual host configuration, nginx.conf file configuration, and log file cutting, recorded as follows:

Nginx Virtual Host Configuration:
1, IP address configuration,
2. Bind IP address and virtual host
Details:
1, the IP address configuration:
Ifconfig eth0 192.168.0.15 netmast 255.255.255.0
Virtual IP and corresponding server block basic configuration:
Ifconfig eth0:1 192.168.0.180 broadcast 192.168.0.255 netmask 255.255.255.0
Ifconfig eth0:2 192.168.0.181 broadcast 192.168.0.255 netmask 255.255.255.0
2, the configuration of the virtual host
Server block configuration inside Nginx, corresponding to virtual IP and root directory
Simple examples such as
Server
{
Listen 192.168.0.180:80;
server_name 192.168.0.180;
Access_log/home/log/access22.log;
Location/
{
Index.html index.htm index.php;
Root/home/xuni;
}
}
Create the corresponding directories and files so that you can access the 192.168.0.180
Create the/home/log/directory,/home/xuni directory, and Touch index.htm under/home/xuni
You can access the 192.168.0.180 and see the index.htm content,
The virtual host is created

3, Nginx cache configuration and other configuration:
Examples are: Cache configuration
#所有以gif |jpg|swf end of file, cache is retained for 30 days after deletion
Location ~. *\. (gif|jpg|swf) $
{
Expires 30d; #30天释放的意思
}
Example 2
Location ~. *\. (JS|CSS)? $
{
Expires 12h;
}
4, gzip compression configuration: (Can make the original page content compressed into the original 30%, excluding less than 1K,
gzip on; #开启gzip功能
Gzip_min_length 1k; #小于1K的不适合压缩
Gzip_buffers 4 16k; #压缩后的存与内存中, apply for 4 x 16k
Gzip_http_version 1.1; #http的版本
Gzip_vary on; #判断客户端浏览器是否支持gzip技术

5. Automatic column directory configuration: AutoIndex on
Location/
{
Index.html index.htm index.php;
Root/home/xuni;
AutoIndex on; #开启自动列表, read other files when there is no index.html
}

6, the Nginx log file cutting:
Manual cutting: 1, daily Movement, MV Access.log > Time.log 2, KILL-USR1 PID
Automatic cutting: Writing scripts, crontab scheduled Tasks
The automatic cut script content is as follows:
CD Nginxlog_dir
d=$ (Date +%y%m%d)
Mv/nginxlog_dir/access.log ${d}.log
KILL-USR1 $ (cat/usr/local/nginx/nginx.pid)

Virtual host IP configuration, nginx.conf file configuration and log file cutting

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.