| 关键词: nbsp forum rewrite 配置 php FastCGI index user location bsp |
配置文件与说明 通用配置user nginx; worker_processes 16; #根据cpu核数确定 error_log /web/log/nginx-error.log; pid logs/nginx.pid; events { use epoll; #使用epoll方式 worker_connections 8192; } http { #通用配置选项 include mime.types; default_type application/octet-stream; server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_max_body_size 8m; #性能优化选项 sendfile on; tcp_nopush on; keepalive_timeout 60; tcp_nodelay on; #FastCGI通用配置 fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 64k; fastcgi_buffers 4 64k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 128k; #Gzip压缩选项 gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_comp_level 6; gzip_types text/plain application/x-javascript text/css application/xml; gzip_vary on; #日志格式 log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; #默认server server { listen 80 default; root /dev/null; location / { return 404; access_log off; } } #包含其他配置文件的路径,此处是相对主程序路径 include conf.d/*.conf; } 详细配置server { listen 80 ; server_name .........; index index.html index.php; root /web/wwwroot/snapB/app/webroot; include block.conf; #关键词过滤配置文件 #rewrite规则,前两条是为了访问二级域名时跳转到三级域名,后面几条是因为搜索引擎收录了我们错误的url if ($host = '......') { rewrite ^/(.*)$ http://....../$1 permanent; } if ($host = '.......') { rewrite ^/(.*)$ http://......./$1 permanent; } #根据user-agent阻止恶意流量 if ($http_user_agent ~* ".*(Huaweisymantecspider|huaweisymantecspider|Wget|wget|robot|spideri|MJ12bot|HTTrack|crawl|Python|python|Java|java|Perl|perl|PHP|php).*") { set $var_bad_user_agent '1'; } if ($http_user_agent ~ "^$") { set $var_bad_user_agnet '1'; } if ($http_user_agent ~* ".*(BaiDu|Sougou|Google).*") { set $var_bad_user_agent '0'; } if ($var_bad_user_agent ~ '1') { return 403; } location / { # For bbpress if ($uri ~ ^/forum){ break; } #cakephp配置 if (-f $request_filename) { break; } if (!-f $request_filename) { rewrite ^/(.+)$ /index.php?url=$1 last; break; } } #forum虚拟目录和rewrite规则 location /forum { alias /web/wwwroot/snapB/app/forum; index index.php; if (!-e $request_filename) { rewrite ^/forum/topic/(.*)$ /forum/topic.php?q=$1 last; rewrite ^/forum/forum/(.*)$ /forum/forum.php?q=$1 last; rewrite ^/forum/profile/(.*)$ /forum/profile.php?q=$1 last; rewrite ^/forum/view/(.*)$ /forum/view.php?q=$1 last; rewrite ^/forum/tags/(.*)$ /forum/tags.php?q=$1 last; rewrite ^/forum/rss/(.*)$ /forum/rss.php?q=$1 last; rewrite ^/forum/bb-admin/ /forum/bb-admin/index.php last; rewrite ^/forum/ /forum/index.php last; break; } } #客户端缓存javascript配置 location /js { expires max; } location /css { expires max; } location /img { expires max; } #php-fpm配置 location ~ .*\.(php|php5)?$ { # For bbpress if ($uri ~ ^/forum){ root /web/wwwroot/snapB/app/; } fastcgi_pass unix:/dev/shm/php-fpm.sock; fastcgi_index index.php; include fcgi.conf; } access_log /web/log/........log main; } |
|
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系
[邮箱地址] 删除
|