NGINX配置詳解:http://blog.csdn.net/tjcyjd/article/details/50695922
Nginx主配置(預設虛拟主機)檔案:/usr/local/nginx/conf/nginx.conf
添加的虛拟主機配置檔案:/usr/local/nginx/conf/vhost/域名.conf
vim /usr/local/nginx/conf/nginx.conf
防止IP通路伺服器 加在 http { } 裡面 每個server{}都是寫在http{}裡面。
server
{
listen 80 default;
listen 82 default;
return 404;
}
(1)cpu有多少個核,就有幾位數,1代表核心開啟,0代表核心關閉
(2)worker_processes最多開啟8個,8個以上性能就不會再提升了,而且穩定性會變的更低,是以8個程序夠用了
參考:http://www.php230.com/set-worker-cpu-affinity-to-up-nginx-performance.html
user www www;
worker_processes auto; //工作程序:數目。根據硬體調整,通常等于CPU數量或者2倍于CPU。
worker_cpu_affinity auto;
error_log /home/wwwlogs/nginx_error.log crit;
pid /usr/local/nginx/logs/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 51200;
//每個程序允許的最多連接配接數根據硬體調整,和前面工作程序配合起來用,盡量大,但是别把cpu跑到100%就行。每個程序允許的最多連接配接數,
理論上每台nginx伺服器的最大連接配接數為。worker_processes*worker_connections
multi_accept on;
}
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 50m; //設定通過nginx上傳檔案的大小
sendfile on;
tcp_nopush on;
keepalive_timeout 60; // 連接配接逾時時間
tcp_nodelay on;
fastcgi_connect_timeout 600;
fastcgi_send_timeout 600;
fastcgi_read_timeout 600;
fastcgi_buffer_size 128k;
fastcgi_buffers 16 128k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain image/jpeg application/javascript application/x-javascript text/javascript text/css application/xml application/xml+rss;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";
#limit_conn_zone $binary_remote_addr zone=perip:10m;
##If enable limit_conn_zone,add "limit_conn perip 10;" to server section.
server_tokens off;
access_log off;
upstream phpbackend{
server unix:/tmp/php-cgi.sock weight=100 max_fails=5 fail_timeout=5;
server unix:/tmp/php-cgi-2.sock weight=50 max_fails=5 fail_timeout=5;
keepalive 24;
}
server //default的server被禁止IP通路了
{
listen 80 default;
listen 82 default;
return 404;
}
server //每個server代表一個虛拟主機
{
listen 80;
listen 82;
server_name admin.***.com sp.***.com sp.wt***.com newpic.***.com jiekou.***.com api.***.com pic.***.com;
index index.html index.htm index.php;
root /home/wwwroot/default;
#error_page 404 /404.html;
#include enable-php.conf;
location ~ /php_count {
include fastcgi.conf;
fastcgi_pass unix:/tmp/php-cgi.sock;
access_log off;
}
location ~ [^/]\.php(/|$)
{
try_files $uri =404;
# fastcgi_pass phpbackend;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
proxy_http_version 1.1;
proxy_set_header Connection "";
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h; location ~ /\.
{
deny all;
}
access_log /home/wwwlogs/access.log;
#access_log off;
#log_not_found off;
}
include vhost/*.conf; //包含進 vhost目錄下的所有虛拟主機 lnmp vhost add 添加進來的
}
}
server
{
listen 80;
listen 82;
server_name www.***.cc www.***.com www.***.com www.***ske.com tg.ios***.cc www.ks***.com www.xiao***.com www.ws***.com img.***.com;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/www.***888.com;
include none.conf;
#error_page 404 /404.html;
#include enable-php.conf;
location ~ [^/]\.php(/|$)
{
try_files $uri =404;
# fastcgi_pass phpbackend;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /\.
{
deny all;
}
access_log /home/wwwlogs/www.xiaoya888.com.log;
#access_log off;
#log_not_found off;
}