user root;
worker_processes 1;
error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include 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 logs/access.log main;
sendfile on;
#tcp_nopush on;
client_max_body_size 5m; #上传文件限制5m
#keepalive_timeout 0;
keepalive_timeout 65;
proxy_connect_timeout 300;
proxy_send_timeout 300;
proxy_read_timeout 300;
#gzip on;
#配置转发到tomcat
upstream webservers {
server 192.168.0.13:8080 weight=1;
server 192.168.0.14:8080 weight=1;
}
server {
listen 80;
server_name localhost;
#charset koi8-r;
access_log logs/host.access.log combined;
#负载均衡proxy_pass,及日志获取客户端ip
location / {
proxy_pass http://webservers;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
#隐藏nginx版本号
server_tokens off;
proxy_hide_header X-Powered-By;
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
#禁止访问index.php
location ~* /index.php {
deny all;
}
# HTTPS server
#
server {
listen 443;
server_name localhost;
ssl on;
#root html;
#index index.html index.htm;
ssl_certificate cert/214885830680519.pem;
ssl_certificate_key cert/214885830680519.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://webservers;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
server_tokens off;
proxy_hide_header X-Powered-By;
location ~* /index.php {
deny all;
}
}
}