Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
370 views
in Technique[技术] by (71.8m points)

How to setup nginx multiple apps and mutiple ports with one ssl

I have already deployed in HTTPS. This is my nginx.conf

server {
  listen 3000 ssl;
  listen [::]:3000 ssl;

  server_name localhost hostname.com;
  ssl_certificate      ssl-bundle.crt;
  ssl_certificate_key  privatekey.pem;
  add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";

      location / {
            proxy_set_header X-Forwarded-For            $proxy_add_x_forwarded_for;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header Host $http_host;
        
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
        
            proxy_pass http://127.0.0.1:4000/;
            proxy_redirect off;
            proxy_read_timeout 240s;
      }
}

I want to run new app with new port on the same domain, I try to add this:

server {
  listen 4000 ssl;
  listen [::]:4000 ssl;

  server_name localhost hostname.com;
  ssl_certificate      ssl-bundle.crt;
  ssl_certificate_key  privatekey.pem;
  add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";

      location / {
            proxy_set_header X-Forwarded-For            $proxy_add_x_forwarded_for;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header Host $http_host;
        
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
        
            proxy_pass http://127.0.0.1:8000/;
            proxy_redirect off;
            proxy_read_timeout 240s;
      }
}

When run two app I can use https only port 3000 but can not use app on port 4000. How to config file?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...