server { listen 80; server_name www.heboan.com heboan.com; access_log /data/logs/nginx/www_heboan_com.asscess.log main; location / { proxy_pass http://127.0.0.1:8080; proxy_redirect default; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_connect_timeout 30; proxy_send_timeout 60; proxy_read_timeout 60; proxy_buffer_size 32k; proxy_buffering on; proxy_buffers 4 128k; proxy_busy_buffers_size 256k; proxy_max_temp_file_size 256k; } }
优化配置,我们可以把一些公用的proxy参数放置到一个文件里面
# vim proxy_params proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_connect_timeout 30; proxy_send_timeout 60; proxy_read_timeout 60; proxy_buffer_size 32k; proxy_buffering on; proxy_buffers 4 128k; proxy_busy_buffers_size 256k; proxy_max_temp_file_size 256k; 然后我们在nginx配置文件中只要需要包含proxy_params就可以 server { listen 80; server_name www.heboan.com heboan.com; access_log /data/logs/nginx/www_heboan_com.asscess.log main; location / { proxy_pass http://127.0.0.1:8080; proxy_redirect default; include proxy_params; } }