1.nginx.conf的配置如下,nginx的监听端口是80 ,对应项目的启动端口分别是8020对应的域名是dianyu.site,8020前面的ip为本机的本地ip这样访问速度比较快不能使用外网ip,这是第一个server的配置,第二个的配置对应项目端口是8080,启用了一个二级域名oa.dianyu.site
#user nobody;
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 {
server {
# nginx的监听端口
listen 80;
# 对应的域名
server_name dianyu.site;
location /{
# 对应的项目启动的本机ip和对应项目启动的端口
proxy_pass http://106.13.55.232:8020;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
gzip on;
gzip_min_length 1k;
gzip_buffers 16 64k;
gzip_http_version 1.1;
gzip_comp_level 6;
gzip_types text/plain application/x-javascript text/css application/xml image/jpeg image/gif image/png;
gzip_vary on;
proxy_connect_timeout 3;
proxy_read_timeout 600;
proxy_send_timeout 600;
proxy_buffer_size 64k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
#proxy_pass http://tomcat;
}
# 对应的本端口的nginx的日志
access_log logs/tomcat1_access.log;
}
server {
listen 80;
server_name oa.dianyu.site;
location /{
proxy_pass http://106.13.55.232:8080;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
gzip on;
gzip_min_length 1k;
gzip_buffers 16 64k;
gzip_http_version 1.1;
gzip_comp_level 6;
gzip_types text/plain application/x-javascript text/css application/xml image/jpeg image/gif image/png;
gzip_vary on;
proxy_connect_timeout 3;
proxy_read_timeout 600;
proxy_send_timeout 600;
proxy_buffer_size 64k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
#proxy_pass http://tomcat;
}
access_log logs/tomcat2_access.log;
}
}