配置前你需要有的:
-
jdk环境
-
tomcat环境
-
nginx环境
-
配置前你需要清楚的:
-
nginx的pid位置(默认是在/usr/local/nginx/logs/nginx.pid)
-
nginx启动命令的位置(我博客里的位置是/usr/loca/nginx/sbin/nginx)
-
nginx配置文件的位置(我博客里的位置是/usr/local/nginx/nginx.conf)
-
nginx的lockfile位置(默认位置是/usr/local/nginx/nginx.conf)
-
首先,修改nginx的配置文件
[root@unique nginx]# vim /usr/local/nginx/nginx.conf
#运行nginx所在的用户名和用户组
#user nobody;
#启动进程数
worker_processes 8;
#全局错误日志及PID文件
error_log /usr/local/nginx/logs/nginx_error.log crit;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid /usr/local/nginx/logs/nginx.pid;
#工作模式及连接数上限
events {
use epoll;
worker_connections 1024;
}
#设定http服务器,利用它的反向代理功能提供负载均衡支持
http {
#设定mime类型
include mime.types;
default_type application/octet-stream;
#设置代理(下面有代理文件的配置)
include /usr/local/nginx/conf/proxy.conf;
#设定请求缓冲
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
#client_max_body_size 10m;
#定义访问日志的写入格式
log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
access_log /usr/local/nginx/logs/localhost.log access;#设定访问日志的存放路径
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
#root html;
#index index.html index.htm;
proxy_pass http://127.0.0.1:8080; #注释默认两行,新增一行。
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
#重新启动你的nginx
#启动tomcat
代理文件的位置:/usr/local/nginx/conf/proxy.conf
#!nginx (-)
# proxy.conf
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; #获取真实ip
#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #获取代理者的真实ip
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;