Nginx key optimization combined with one

Source: Internet
Author: User
Tags dateformat

Nginx Features

    • Supports high concurrency

    • Low resource consumption

    • Load Balancing

    • Caching features

    • Support for asynchronous networks

Nginx Virtual Host

Worker_processes 1;

Events {

Worker_connections 1024;

}

HTTP {

Include Mime.types;

Default_type Application/octet-stream;

Sendfile on;

Keepalive_timeout 65;

include extra/www.conf;

Include extra/blog.conf;

Include extra/status.conf;

}

Vim.. /conf/extra/www.conf

server {

Listen 80;

server_name www.hequan.com hequan.com;

Location/{

root html/www;

Index index.html index.htm;

}

}

server {

Listen 80;

server_name status.hequan.com;

Location/{

stub_status on; Turn on status information switch

Access_log off;

}

}

Nginx Log

Error Log//Official document Http://nginx.org/en/docs/ngx_core_module.html#error_log

Nginx Key Optimization Combined set

Error_log Logs/error.log error; Keyword log file error log level: General use Warn|error|crit crit to record minimum error information

Error_log/dev/null Crit; Turn off log information logging

Access Log//http://nginx.org/en/docs/http/ngx_http_log_module.html

Log_format Main ' $remote_addr -$remote_user [$time _local] "$request" '

' $status $body_bytes_sent ' $http _referer "'

' $http_user_agent' "$http _x_forwarded_for" ';

Access_log logs/access.log main gzip buffer=32k flush=5s; Placed in the http,server,localtion,if in Localtion,limit_except

Cutting logs

Script Cutting

Vim cut_nginx_log.sh//Rename the Nginx log to a new file with a date format, then smooth restart, generate a new log

#!/bin/sh

dateformat= ' Date +%y%m%d '

Basedir= "/application/nginx"

Nginxlogdir= "$Basedir/logs"

Logname= "Access"

[-D $Nginxlogdir] && CD $Nginxlogdir | | Exit 1

[-F ${logname}.log] | | Exit 1

/bin/mv ${logname}.log ${logname}_ ${dateformat}. Log

$Basedir/sbin/nginx-s Reload



Cat >>/var/spool/cron/root <<eof

#cut nginx Access Log by Hequan

XX * * * */bin/sh/hequan/sh/cut_nginx_log.sh >/dev/null 2>&1

Eof


Add

#删除7天前的日志

Find. -mtime +7-name "20[1-9][1-9]*" | Xargs rm-f

Open Nginx catalog File list display function


Normal access Nginx words is to display the Nginx Welcome page, that is,/nginx/html/index.html file;

If you want to display all the files in the/html/directory, you need to open the directory file list display;

In the nginx.conf master configuration file in the HTTP or Location code snippet, configure a piece of code can be implemented;

HTTP {

Include Mime.types;

Default_type Application/octet-stream;

AutoIndex on;

Autoindex_exact_size off;

Autoindex_localtime on;

AutoIndex on; automatic display of catalogs

Autoindex_exact_size off;

The default is on to show the exact size of the file, in bytes.

After change to off, the approximate size of the file is displayed, in kilobytes or MB or GB

Autoindex_localtime on;

The default is off, and the file time displayed is GMT time.

When on, the file time displayed is the server time of the file

Location match identifies the configuration segment to be executed after matching the URL configuration uri of the Web site

~ Case-sensitive ~* case-insensitive ^~ do not check regular expressions after regular matching

Location ^~ /images/{

return 404;

}

Location ~* \. (GIF|JPG|JPEP)  $ {//Regular match

return 500;

}

Location =/{}//Exact match

location/documents/{}//Match regular string with regular, first match regular

Location/{} All lcoation cannot match after default match

Nginx rewrite implementation of URL address rewriting

Server hequan.com;

rewrite ^/(. *) http://www.hequan.com/$1 permanent; $1= (. *)

Permanent is permanently 301 redirect after last match, continue to match down break configuration and terminate redirect return 302 temporary redirect

Nginx Access Log

Location/{

Auth_basic "prompt character";

Auth_basic_user_file conf/htpasswd;

}//Use Apache htpasswd to generate password files

Yum-y Install Httpd-tools

Htpasswd-c-m/application/nginx/conf/htpasswd Hequan

Lnmp

Nginx PHP5 MySQL

Fastcgi_pass→fastcgi←→ mysql_connet () →connect dbms→

mysql_select_db () →connect database→ data




This article is from the "what-all" blog, please be sure to keep this source http://hequan.blog.51cto.com/5701886/1784366

Nginx key optimization combined with one

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.