nginx默认配置文件
user root;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
include /etc/nginx/conf.d/*.conf;
}
/etc/nginx/conf.d/default.conf
WEB服务和文件服务。
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
location /file {
root /root;
autoindex on;
sendfile on;
autoindex on;
autoindex_exact_size on;
autoindex_localtime on;
charset utf-8,gbk;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
/etc/nginx/conf/prox.conf
反向代理服务
upstream tomcatServer {
server 192.168.56.101:8080;
}
server {
listen 81;
server_name localhost;
location / {
proxy_pass http://tomcatServer;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
/etc/nginx/upstream.conf
负载均衡服务
upstream tomcatServerGroup {
server 192.168.56.101:8180;
server 192.168.56.101:8280;
server 192.168.56.101:8380;
}
server {
listen 82;
server_name localhost;
location / {
proxy_pass http://tomcatServerGroup;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}