Nginx服务器nginx.conf的配置文件说明.
user www-data;
worker_processes 1;
error_log /logs/nginx/error.log;
pid /logs/mginx/nginx.pid;
events {
use epoll;
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
access_log /logs/nginx/access.log;
sendfile on;
keepalive_timeout 65;
tcp_nodelay on;
gzip on;
gzip_disable "MSIE [1-6].(?!.*SV1)";
client_header_buffer_size 1k;
large_client_header_buffers 4 4k;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
server {
listen 80;
server_name http://www.pekingpiao.com;
access_log /logs/nginx/www.pekingpiao.com.access.log main;
location / {
root /var/www/html;
index index.php index.html index.htm;
fastcgi_pass http://www.pekingpiao.com;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ ^/(images|javascript|js|css|flash|media|static)/ {
root /var/www/html;
expires 30d;
}
location ~ \.php$ {
root /var/www/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/www/www$fastcgi_script_name;
include fastcgi_params;
}
location /NginxStatus {
stub_status on;
access_log on;
auth_basic "NginxStatus";
auth_basic_user_file conf/htpasswd;
}
location ~ /.ht {
deny all;
}
}
}
以上是一些基本的配置,使用Nginx最大的好处就是负载均衡
如果要使用负载均衡的话,可以修改配置http节点如下:
http {
include mime.types;
default_type application/octet-stream;
access_log /logs/nginx/access.log;
upstream myserver {
server 192.168.18.1:3128 weight=5;
server 192.168.18.2:80 weight=1;
server 192.168.18.3:80 weight=6;
}
upstream myserver2 {
server 192.168.8.x:80 weight=1;
server 192.168.8.x:80 weight=6;
}
server {
listen 80;
server_name 192.168.8.x;
location ~ .*.php$ {
root /var/www/html;
index index.php index.html index.htm;
proxy_pass http://myserver ;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
}
}
|