Linux

使用相同的公共埠執行兩個服務

  • December 6, 2014

假設我已經http://localhost:8080 指向我的 Jenkins 實例並http://localhost:8081指向我的 Jira 實例,我需要做些什麼來訪問我的服務,比如http://localhost/jenkins使用http://localhost/jira預設埠 80?這在 Ubuntu 中可能嗎?

NGINX 作為反向代理執行的配置片段

http {

 # Some standard NGINX config stuff goes here
 ...

 # Listen on port 80
 server {
   listen 80;
   server_name my.awesome.domain.com;

   # Proxy /jenkins to localhost port 8080
   location /jenkins {
     proxy_pass http://localhost:8080;
   }

   # Proxy /jira to localhost port 8081
   location /jira {
     proxy_pass http://localhost:8081;
   }
 }
}

有關更多資訊,請參閱NGINX文件。

Apache 作為反向代理執行的配置片段

# First load the reverse proxy modules
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so

# Make sure we're listening on port 80    
Listen 80

# Define a default vHost
<VirtualHost *:80>

 # Standard vhost stuff goes here if required
 # Probably should have something to handle / requests at least
 ....

 # Reverse proxy for Jenkins
 ProxyPass /jenkins http://localhost:8080
 ProxyPassReverse /jenkins http://localhost:8080

 # Reverse proxy for Jira
 ProxyPass /jira http://localhost:8081
 ProxyPassReverse /jira http://localhost:8081

</VirtualHost>

有關更多資訊,請參閱Apache文件

引用自:https://serverfault.com/questions/649569