作者:Chilldon螴暁鼕 | 来源:互联网 | 2023-09-11 04:41
error_log/usr/local/nginx/logs/nginx_error.logcrit;pid/usr/local/nginx/logs/nginx.pid;
error_log /usr/local/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile ;
events
{
use epoll;
worker_connections ;
}
{
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size ;
server_names_hash_max_size ;
log_format combined_realip $remote_addr $http_x_forwarded_for [$time_local]
$host $request_uri $status
$http_referer $http_user_agent
sendfile on;
tcp_nopush on;
keepalive_timeout ;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
connection_pool_size ;
client_header_buffer_size 1k;
large_client_header_buffers 4k;
request_pool_size 4k;
output_buffers 32k;
postpone_output ;
client_max_body_size 10m;
client_body_buffer_size 256k;
client_body_temp_path /usr/local/nginx/client_body_temp;
proxy_temp_path /usr/local/nginx/proxy_temp;
fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
fastcgi_intercept_errors on;
tcp_nodelay on;
gzip on;
gzip_min_length 1k;
gzip_buffers 8k;
gzip_comp_level ;
gzip_http_version 1.1;
gzip_types text/plain application/x-Javascript text/css text/htm application/xml;
include vhosts/*.conf;
cd /usr/local/nginx/conf/
mkdir vhosts
touch discuz.conf
touch pma.conf
touch blog.conf
14.discuz.conf
server
{
listen 80;
server_name bbs.abc.com;
index index.html index.htm index.php;
root /data/bbs;
#根据user_agent控制
if ($http_user_agent ~ bingbot/2.0|MJ12bot/v1.4.2|Spider/3.0|YoudaoBot|Tomato|Gecko/20100315 ){
return 403;
}
location ~ admin.php {
allow 192.168.31.141;
deny all;
proxy_pass http://127.0.0.1:88;
proxy_set_header Host $host;
location ~ \.php$ {
proxy_pass http://127.0.0.1:88;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
location ~ .*\.(js|css)?$
{
expires 24h;
access_log off;
location ~* ^.+\.(gif|jpg|png|swf|flv|rar|zip|doc|pdf|gz|bz2|jpeg|bmp|xls)$ {
expires 7d;
valid_referers none blocked server_names *.abc.com *.a.com *.b.com *.baidu.com\
*.google.com *.google.cn *.soso.com ;
if ($invalid_referer) {
return 403;
#rewrite ^/ http://www.example.com/nophoto.gif;
}
access_log off;
rewrite ^([^\.]*)/topic-(.+)\.html$ $1/portal.php?mod=topic topic=$2 last;
rewrite ^([^\.]*)/forum-(\w+)-([0-9]+)\.html$ $1/forum.php?mod=forumdisplay fid=$2 page=$3 last;
rewrite ^([^\.]*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=viewthread tid=$2 extra=page%3D$4 page=$3 last;
rewrite ^([^\.]*)/group-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=group fid=$2 page=$3 last;
rewrite ^([^\.]*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space $2=$3 last;
rewrite ^([^\.]*)/(fid|tid)-([0-9]+)\.html$ $1/index.php?action=$2 value=$3 last;
access_log /home/logs/discuz.log combined_realip;
检测nginx配置文件:
/usr/local/nginx/sbin/nginx -t
重启
nginx:service nginx restart
在浏览器访问bbs.abc.com,是可以正常进入discuz页面的。
15.blog.conf配置(参考 http://www.upupw.net/nginxhelp/n33.html)
server
{
listen ;
server_name blog.abc.com;
index index.html index.htm index.php;
root /data/blog;
location /wp-admin/ {
allow 127.0.0.1;
deny all;
location ~ \.php$ {
proxy_pass http://127.0.0.1:88;
proxy_set_header Host $host;
}
location / {
proxy_pass http://127.0.0.1:88/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
检测nginx配置文件是否有语法错误:
/usr/local/nginx/sbin/nginx -t
重启nginx:
service nginx restart
在浏览器访问:blog.abc.com,是可以访问的
16.配置pma.conf
server
{
listen ;
server_name pma.abc.com;
index index.html index.htm index.php;
root /data/pma;
location / {
auth_basic Auth
auth_basic_user_file /usr/local/nginx/conf/htpasswd;
location ~ \.php$ {
proxy_pass http://127.0.0.1:88;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
检测nginx配置文件是否有语法错误:
/usr/local/nginx/sbin/nginx -t
重启nginx:
service nginx restart
浏览器访问:pma.abc.com是可以访问到的
17、配置nginx的日志切割
[root@lanp vhosts]# vim /usr/local/sbin/logrotate.sh
#!/bin/bash
d=`date -d - day +%Y%m$d`
/bin/mv /home/logs/discuz.log /home/logs/discuz_$d.log
/etc/init.d/nginx reload /dev/null /dev/null
cd /home/logs
gzip discuz_$d.log
18、mysql备份脚本无需密码通过ssh执行rsync来同步文件的方法可以参考http://www.jb51.net/article/60192.htm
vim mysqlbak.sh
#!/bin/bash
source /etc/profile
d=`date +%F`
/usr/local/mysql/bin/mysqldump -uroot -p838024 wordpress /data/mysqlbak/$d.wordpresssql
/usr/local/mysql/bin/mysqldump -uroot -p838024 discuz /data/mysqlbak/$d.discuzsql
/usr/local/mysql/bin/mysqldump -uroot -p838024 phpmyadmin /data/mysqlbak/$d.phpmyadminsql
rsync -avLupz -e ssh -p /data/mysqlbak/ 192.168.137.107:/tmp/
再把脚本放进crontab计划任务
chmod a+x mysqlbak.sh
crontab -e
*/ * * * * /root/shell/mysqlbak.sh
关于rsync命令:
本地和远程需要安装rsync和openssh-clients
yum install rsync和yum install openssh-clients