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
- #!/bin/bash
- Log_path="/opt/nginx/logs"
- Dir_name= ' date-d "Yesterday" +%y%m '
- File_name= ' date-d "Yesterday" +%y.%m_%d '
- Mkdir-p ${log_path}/${dir_name}
- MV ${log_path}/access.log ${log_path}/${dir_name}/${file_name}.log
- 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
- Ls-al
- chmod 744 split-nginx-log.sh
- ./split-nginx-log.sh
3. Scheduled scheduling: 0-point cutting log per day
Shell Code
- Crontab-e
- 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
- Nginx_home=/usr/local/nginx
- Path= $NGINX _home/sbin: $PATH
- Export PATH
Immediate effect: source. bash_profile
2. Start and close:
Shell Code
- Nginx-c/usr/local/nginx/conf/nginx.conf
- Nginx-s quit
3. Executable script:
Start: VI start-nginx.sh
Shel Code
- Nginx-c/usr/local/nginx/conf/nginx.conf
Close: VI stop-nginx.sh
Shell Code
- Nginx-s quit
Execute permissions:
Shell Code
- chmod 744 start-nginx.sh
- chmod 744 stop-nginx.sh
Execute script:
Shell Code
- ./start-nginx.sh
- ./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.