NGINX 作为 tomcat6 的负载均衡器仅给出错误的网关错误,仅限 HTTPS 模式

NGINX 作为 tomcat6 的负载均衡器仅给出错误的网关错误,仅限 HTTPS 模式

我在 tomcat6 web 服务器上使用 nginx 作为负载均衡器。NGINX 和 TOMCAT6 都已配置为使用仅 HTTPS.NGINX 配置设置在以下两个文件中提到。

nginx.conf

user www-data;
worker_processes 4;
pid /var/run/nginx.pid;

events {
        worker_connections 768;
        # multi_accept on;
}

http {

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        # server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ##
        # Logging Settings
        ##

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##

        gzip on;
        gzip_disable "msie6";

        # gzip_vary on;
        # gzip_proxied any;
        # gzip_comp_level 6;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;
        # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

        ##
        # nginx-naxsi config
        ##
        # Uncomment it if you installed nginx-naxsi
user www-data;
worker_processes 4;
pid /var/run/nginx.pid;

events {
        worker_connections 768;
        # multi_accept on;
}

http {

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        # server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ##
        # Logging Settings
        ##

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##

        gzip on;
        gzip_disable "msie6";

        # gzip_vary on;
        # gzip_proxied any;
        # gzip_comp_level 6;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;
        # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

        ##
        # nginx-naxsi config
        ##
        # Uncomment it if you installed nginx-naxsi
        #passenger_root /usr;
        #passenger_ruby /usr/bin/ruby;

        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}

并且 sites-available/default 如下

upstream backend {
server 10.1.2.4;
}

server {


#HTTPS_ENABLED
    listen   443 ssl;
    ssl_certificate        %SSL_CERT%;
    ssl_certificate_key    %SSL_KEY%;
    ssl_ciphers            ALL:!ADH:!kEDH:!SSLv2:!EXPORT40:!EXP:!LOW;
    ssl_session_cache      shared:SSL:10m;
    ssl_session_timeout    10m;
#HTTPS_ENABLED


    location / {
       proxy_pass https://backend;
       proxy_set_header Host $host;
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

如果我使用 https 链接直接连接 Web 服务器,我就可以访问 Web 应用程序

1)tomcat 已启动并正在运行,正在监听 443

2)访问日志中没有可疑内容

但如果我使用 nginx url(https),它会给我“502 bad gateway”错误。我在 nginx 的 access.log 和 error.log 中都找不到任何错误或可疑警告。这里可能出了什么问题?请帮忙

答案1

尝试这个:

upstream backend {
   server 10.1.2.4:443;
}

编辑:为了完整起见,我认为这也是另一种解决方案:

upstream backend {
   server 10.1.2.4 ssl;
}

相关内容