Nginx常用功能汇总

==================Nginx日志分割脚本=======================

#] vim nginx_log_cut.sh

#!/bin/bash

#auto mv nginx log shell

S_LOG=/data/logs/nginx/access.log ##source 源日志

D_LOG=/data/backup/`data +%Y%m%d`

echo -e "\033[32m Please wait start cut shell script....\033[1m"

sleep 1

if [ ! -d $D_LOG];then

mkdir -p $D_LOG ;

cd $D_LOG; tar czf access.log.tar.gz * ; rm -rf access.log; ##可以打包Access.log删除

fi

mv $S_LOG $D_LOG

kill -USR1 `cat /var/run/nginx/nginx.pid`

echo "-------------------------------------------------------------------------"

echo "The nginx logs cutting successgfully!!"

crontab -e 执行

add_header X-Frame-Options SAMEORIGIN;

#include /alidata/server/nginx/conf/rewrite/prettyyes.conf;

if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})")

{

set $year $1;

set $month $2;

set $day $3;

set $hour $4;

set $minutes $5;

set $seconds $6;

}

#### nginx 分割日志一定要放在后面, nginx-$year-month不生效;

access_log /mnt/data/www/how/storage/logs/nginx_access-$year-$month-$day.log; ###

==================Nginx平滑升级==============

https://www.centos.bz/2017/07/nginx-upgrade-latest-version/

使用make upgrade替换老的nginx进程 (需要看版本)

[root@ittestserver1 nginx-1.12.1]# make upgrade

/usr/local/nginx2/sbin/nginx -t

nginx: the configuration file /usr/local/nginx2/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx2/conf/nginx.conf test is successful

kill -USR2 `cat /usr/local/nginx2/logs/nginx.pid`

sleep 1

test -f /usr/local/nginx2/logs/nginx.pid.oldbin

kill -QUIT `cat /usr/local/nginx2/logs/nginx.pid.oldbin`

==============================配置Nginx 服务器解析 PHP =================================

root@iZuf63ay63gn6dhm037ny8Z:/etc/nginx/conf.d# vi test.com.conf

server{

   listen 80;

   server_name test.com;

   #加了这个可使用 index.php路由重写,不加index.php也可以

  location / {

     try_files $uri $uri/ /index.php?$query_string;

  }

  location ~ index\.php?.*$ {

     #rewrite ^/(.*)$ /$1.php last;

    fastcgi_split_path_info ^(.+\.php)(/.+)$;

    index index.php index.html index.htm;

   root /var/www/html/laravel/public/;

   fastcgi_pass 127.0.0.1:9000;

   fastcgi_index index.php;

   fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

   include fastcgi_params;

  }

}

=============================配置站点域名 支持SSL 访问============================

server {

listen 443;

server_name 你网站的域名;

ssl on;

root html;

index index.html index.htm;

ssl_certificate cert/你的证书文件名.pem;

ssl_certificate_key cert/你的证书文件名.key;

ssl_session_timeout 5m;

ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;

ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on;

location / { root html; index index.html index.htm; }

}

5. 重启Nginx,这时候你的站点应该就已经可以通过https方式访问了

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值