nginx配置监听不同端口,实现访问对应不同项目服务
服务器:Centos7
nginx version: nginx/1.23.1
①目前tomcat启动一个java项目,tomcat实际运行端口18082 nginx监听端口80
②springboot的jar包项目启动运行,实际运行占用端口9522 nginx监听端口19522
现在浏览器访问:www.r2cool.cn ==> nginx正常监听80端口,访问tomcat项目正常
但是,访问:www.r2cool.cn:19522 ==> 打不开,要能监听到19522端口,访问到springboot项目
另外,19522能监听的话,如下配置,域名能从http解析成https嘛?
Nginx配置文件如下:
user root;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
#include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] $status '
'"$request" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
##监听tomcat跑的项目 实际端口18082
server {
listen 80;
server_name www.r2cool.cn;
rewrite ^(.*) https://$server_name$1 permanent;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-Ip $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://120.21.121.162:18082;
}
}
##spingboot跑的项目-实际端口9522
upstream r2cool {
server 120.21.121.162:9522;
}
server {
listen 19522;
server_name www.r2cool.cn;
rewrite ^(.*) https://$server_name$1 permanent;
# pass requests for dynamic content to rails/turbogears/zope, et al
location / {
proxy_pass http://r2cool;
}
}
server{
listen 443 ssl;
server_name folio.codingce.com.cn;
ssl_certificate /etc/nginx/1_r2cool.cn_bundle.crt;
ssl_certificate_key /etc/nginx/2_r2cool.cn.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
charset utf-8;
location / {
proxy_pass http://120.21.121.162:18082;
}
}
}