您好我正在尝试设置一个nginx作为我在tomcat服务器上运行的应用程序的反向代理。当我尝试通过http访问我的应用程序时工作正常,但当我尝试通过https访问它时,我收到502错误
这里是我的nginx配置文件
user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log notice;
gzip on;
gzip_disable "msie6";
rewrite_log on;
server{
ssl on;
listen 80;
listen 443 ssl;
server_name myapp.local;
ssl_certificate max.local.crt;
ssl_certificate_key server.key;
#ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
#ssl_ciphers RC3:HIGH:!aNULL:!MD5;
#ssl_prefer_server_ciphers on;
ssl_session_timeout 5m;
keepalive_timeout 60;
error_log /var/log/nginx/hybris.log;
rewrite_log on;
set $my_port 9001;
set $my_protocol "http";
if ($scheme = https){
set $myport 9002;
set $my_protocol "https";
}
location / {
if ( $http_user_agent ~ "Chrome"){
#just a proof of concept
return 301 http://$host/AE/en;
}
if ( $http_user_agent ~ "Firefox"){
#just a proof of concept
return 301 http://google.com/;
}
}
location /AE/en {
proxy_pass $scheme://10.0.2.2:$my_port;
proxy_set_header Host $host;
}
location ~(?:/..)?/_ui/(.*) {
proxy_pass http://10.0.2.2:9001/_ui/$1;
proxy_set_header Host $host;
}
}
}
答案 0 :(得分:1)
使用https时,您正在更改端口以及连接到tomcat服务器的方案 - 这实际上没有意义。如果后端服务器位于另一个数据中心,而不是本地网络中,则只能使用https。如果删除$ my_port和$ my_protocol定义并将/ AE / en位置块更改为
,它应该可以正常工作location /AE/en {
proxy_pass http://10.0.2.2:9001;
proxy_set_header Host $host;
}
答案 1 :(得分:-1)
我认为您需要创建两个服务器部分。一个用于侦听端口80,另一个用于侦听端口453,用于https。