nginx+tomcat 反向代理 負載均衡配置


1、nginx的安裝和配置見:http://www.cnblogs.com/ll409546297/p/6795362.html

2、tomcat部署項目到對應的服務器上面並啟動,不詳解

3、在nginx中配置nginx.conf文件: 

user  nobody; 
worker_processes  4;

#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;

    #keepalive_timeout  0;
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;
    upstream tomcat_client { #針對於8080端口實現
        ip_hash;
        server localhost:8080; #如果存在多個部署,寫入地址和端口即可

    }
    server {
        listen       80;
        server_name  localhost; #本地訪問名稱可以修改,針對於外網可以寫成域名

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            proxy_pass http://tomcat_client; 
            proxy_redirect default;
            #設置代理
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
        }

4、啟動nginx就可以訪問自己的項目


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM