The four of nginx in layman's

Source: Internet
Author: User
In the real nginx practice, we usually cut the Nginx access log, that is, a certain period of time to generate a separate Nginx access log file, in order to avoid the existence of large file size log files. On the one hand to help the actual error troubleshooting, more importantly, to facilitate the Nginx to access the file write. At the same time, Nginx installation path can be added to the environment variables, and even can write a startup shutdown script to facilitate practical operation.

<一> . Cutting log files:
1. Scripting: Su-root
Go to home directory: CD ~
Scripting: VI split-nginx-log.sh

Shell Code

    1. #!/bin/bash
    2. Log_path="/opt/nginx/logs"
    3. Dir_name= ' date-d "Yesterday" +%y%m '
    4. File_name= ' date-d "Yesterday" +%y.%m_%d '
    5. Mkdir-p ${log_path}/${dir_name}
    6. MV ${log_path}/access.log ${log_path}/${dir_name}/${file_name}.log
    7. KILL-USR1 ' Cat ${log_path}/nginx.pid '

Detail Description:
1. Date of day before: Date-d "Yesterday" +%y%m%d
2. Create the directory recursively and do not create if it already exists: Mkdir-p ${log_path}/${dir_name}
3. Rename the log file: MV Access.log new.access.log
4. Notify the Nginx master process to reopen the log file: Kill-usr1 ' Cat/opt/nginx/logs/nginx.pid '

2. Give execution permission, execute:

Shell Code

    1. Ls-al
    2. chmod 744 split-nginx-log.sh
    3. ./split-nginx-log.sh

3. Scheduled scheduling: 0-point cutting log per day

Shell Code

    1. Crontab-e
    2. xx XX * * * /root/split-nginx-log.sh

<二> . Set Environment variables:
1. Edit the current user path:
Show Path:echo $PATH
User Home directory: cd ~
Edit the file and append the following: Vi. bash_profile

Shell Code

    1. Nginx_home=/usr/local/nginx
    2. Path= $NGINX _home/sbin: $PATH
    3. Export PATH

Immediate effect: source. bash_profile
2. Start and close:

Shell Code

    1. Nginx-c/usr/local/nginx/conf/nginx.conf
    2. Nginx-s quit

3. Executable script:
Start: VI start-nginx.sh

Shel Code

    1. Nginx-c/usr/local/nginx/conf/nginx.conf

Close: VI stop-nginx.sh

Shell Code

    1. Nginx-s quit

Execute permissions:

Shell Code

    1. chmod 744 start-nginx.sh
    2. chmod 744 stop-nginx.sh

Execute script:

Shell Code

    1. ./start-nginx.sh
    2. ./stop-nginx.sh

Above on the introduction of the four, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.