主配置文件:/etc/nginx/nginx.conf
user nginx;
worker_processes 2;
worker_rlimit_nofile 65535;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
use epoll;
worker_connections 65535;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format mainold '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
log_format main '$remote_addr - $remote_user [$time_iso8601] "$request_method $scheme://$host:$server_port$uri" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" $request_time $upstream_response_time $request_body';
log_format proxy '$remote_addr - $remote_user [$time_iso8601] "$request_method $scheme://$host:$server_port$uri" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" $request_time $upstream_response_time $request_body';
access_log /var/log/nginx/access.log main;
client_max_body_size 200m;
sendfile on;
#autoindex on;
tcp_nopush on;
tcp_nodelay on;
server_tokens off;
keepalive_timeout 65;
server_names_hash_bucket_size 64;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 4;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
underscores_in_headers on;
ignore_invalid_headers on;
include ./conf.d/*.conf;
}
子配置文件:/etc/nginx/conf.d/test.conf
server {
listen 80;
server_name test.com;
root .../.../... ;
index .../.../... ;
access_log .../.../... main;
error_log .../.../... ;
client_max_body_size 10M;
client_body_buffer_size 10240k;
location / {
}
}
负载均衡配置:/etc/nginx/conf.d/load.conf
upstream test {
least_conn;
ip_hash;
server 10.10.10.1:80 weight=2;
server 10.10.10.2:80 weight=1;
}
server{
listen 80;
server_name test.com;
access_log .../.../... main;
error_log .../.../... ;
client_max_body_size 10M;
client_body_buffer_size 10240k;
location / {
proxy_pass http://test;
}
}
PHP中location的详细配置
index index.html index.htm index.php;
location / {
index index.html index.htm index.php;
try_files $uri $uri/ /index.php?$query_string;
}
location ~ ^(.+\.php)(.*)$ {
#root /www/color_portal/public;
# allow 192.168.12.235; #白名单
# deny all; #黑名单(可单独使用)
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_buffer_size 51200k;
fastcgi_buffers 6 51200k;
fastcgi_busy_buffers_size 51200k;
fastcgi_temp_file_write_size 51200k;
fastcgi_intercept_errors on;
}
}
Java中location的详细配置
location / {
proxy_pass http://test;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-for $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
add_header X-Cache $upstream_cache_status;
# proxy_cache_valid 200 304 10m;
# proxy_cache tt_cache;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_max_temp_file_size 0;
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;
}
网友评论