Logo

NGiNX的妙用

最近绑了不少domain在NGiNX上,一直在编辑nginx.conf同一个档案管理起来,还真是眼花啊 = =” 心理就在想有没有比较好的方式做管理呢?! 后来抓新的原始档下来看,发现可以这样做,在http区段的最后面写上
include /usr/local/nginx/conf/conf.d/*.conf;
原先网站设定的server区段就完全移动到/usr/local/nginx/conf/conf.d/这个资料夹底下分别建立档案控制,再建立一个放rewrite规则设定档的资料夹,我的是放在
/usr/local/nginx/conf/rewrite/
这样老子就轻松多了 A_A 不用一直搞nginx.conf,conf.d这个资料夹就放每个网站的设定档,rewrite规则设定档就通通丢在rewrite资料夹底下,有需要再加载就好了,要修改的时候就比较不会眼花撩乱的在查nginx.conf了。这样做nginx.conf会自动读取到conf.d资料夹底下的网站设定档,而网站设定档再依照需求去加载rewrite规则设定档,出现错误也比较清楚是哪边写错了,不会只在nginx.conf上面一直翻;而且日后要新增网站也轻松很多,只要抠比其他的网站设定档改一下网址跟路径以及rewrite规则设定档就好了,感觉效率比较高一些~ ? 下面是我的范例,有兴趣可以参考看看,注意include这个字眼唷!
nginx.conf
user www;
worker_processes 2;
worker_rlimit_nofile 10000;
error_log /var/log/nginx-error.log;
#error_log /var/log/nginx-error.log notice;
#error_log /var/log/nginx-error.log info;
pid /var/run/nginx.pid;
events {
worker_connections 12800;
use epoll;
}
http {
include mime.types;
default_type application/octet-stream;
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 /var/log/nginx-access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
server_tokens off;
gzip on;
gzip_static on;
gzip_comp_level 1;
gzip_buffers 4 16k;
gzip_min_length 1024;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
keepalive_timeout 65;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 128k;
fastcgi_buffers 8 128k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
client_max_body_size 128m;
client_body_buffer_size 128k;
# 暂存资料夹
proxy_temp_path tmp/proxy_temp;
fastcgi_temp_path tmp/fastcgi_temp;
client_body_temp_path tmp/client_body_temp;
# 设定一个叫做myzone的区域,大小为10MB
limit_zone myzone $binary_remote_addr 10m;
# 加载所有虚拟主机设定档
include /usr/local/nginx/conf/conf.d/*.conf;
}

520.be.conf
server {
listen 80;
server_name 520.be;
index index.html index.htm index.php;
root /web/www/520.be;
include /usr/local/nginx/conf/rewrite/wordpress.conf;
# 启用FastCGI
location ~ .*.(php|php5)?$ {
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fcgi.conf;
}
location ~ .*.(ico|gif|jpg|jpeg|png|bmp|flv|swf)$ {
expires 30d;
access_log off;
}
location ~ .*.(js|css)?$ {
expires 12h;
access_log off;
}
}

wordpress.conf
location / {
index index.html index.htm index.php;
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}

关于 穷苦人家的小孩

In every democracy, the people get the government they deserve. ~Alexis de Tocqueville

您可能会喜欢

希志あい 希志爱野 Kishi Aino

VPS介绍 – AlphaVPS

今年黑五很超值的主机商一定要算 …