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;
}