1. 在/usr/local/nginx/conf下面添加文件proxy.conf
# cat /usr/local/nginx/confg/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;
2.配置nginx.conf
# cat /usr/local/nginx/confg/nginx.conf
user www www;
worker_processes 1;
pid /usr/local/nginx/logs/nginx.pid;
events {
use epoll;
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
include /usr/local/nginx/conf/proxy.conf; #一定要指向代理文件
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
charset gb2312;
location / {
root /www/web/ROOT;
index index.html index.htm;
}
location ~ .*.jsp$ { #匹配以jsp结尾的,tomcat的网页文件是以jsp结尾
index index.jsp;
proxy_pass http://127.0.0.1:8080; #主要在这里,设置一个代理
}
location /nginxstatus {
stub_status on;
access_log on;
auth_basic "nginxstatus";
auth_basic_user_file /usr/local/nagois/etc/htpasswd.users;
}
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
3.测试
在/www/web/ROOT下添加文件index.html
# cat index.html
the port:80
重启nginx
http://192.168.2.150/index.jsp