2012-08-27 72 views
3

我有一個fedora服務器。我通過yum包管理器安裝了tomcat。然後我在webapps文件夾中部署了nexus war。 I tryed using jsvc在端口80上運行服務器並且不起作用。我看到你也可以使用port fowarding。什麼是最好的選擇?如何在端口80上運行nexus sonatype?

編輯1:httpd的

我跟着從Sonatype的文檔3.8. Running Nexus Behind a Proxy和我有點困惑。 我安裝了httpd,並且我有以下配置,其中example.com是我的域。

/etc/httpd/conf.d/nexus.conf

NameVirtualHost *:80 

<VirtualHost *:80> 

    ServerName example.com 
    ProxyRequests Off 

    <Proxy *> 
    Order deny,allow 
    Allow from all 
    </Proxy> 

    ProxyPass /nexus/ http://localhost:8081/nexus/ 
    ProxyPassReverse /nexus/ http://localhost:8081/nexus/ 
    ProxyPreserveHost On 

    <Location /> 
    Order allow,deny 
    Allow from all 
    </Location> 

    ErrorLog logs/nexus/error.log 
    CustomLog logs/nexus/access.log common 
</VirtualHost> 

/家庭/紀堯姆/ WWW /關係/ conf目錄

# Jetty section 
application-port=8081 
application-host=0.0.0.0 
nexus-webapp=${bundleBasedir}/nexus 
nexus-webapp-context-path=/nexus 

# Nexus section 
nexus-work=${bundleBasedir}/../sonatype-work/nexus 
runtime=${bundleBasedir}/nexus/WEB-INF 
pr.encryptor.publicKeyPath=/apr/public-key.txt 

,當我嘗試訪問

  • http://localhost:8081/nexus/index.html一切工作
  • http://localhost/nexus/index.html一切正常
  • http://example.com/nexus/index.html只是掛(80端口在防火牆中打開)

    $ netstat的-tulpn |的grep:80

    TCP 0 0 ::: 80 ::: * LISTEN 3965/httpd的
    TCP 0 0 ::: 8081 ::: * LISTEN 3811/JAVA
    UDP 0 0 0.0.0.0:803 0.0 .0.0:* 1051/rpc.statd

有關如何使代理工作的任何線索?

編輯2:nginx的

我發現了錯誤,DNS是錯誤的:nslookup example.com決心x.x.x.x當我的IP是x.x.x.y

但我確實喜歡ngix配置

server { 

     listen 80; 
     server_name example.com; 

     access_log off; 
     error_log off; 

     location/{ 
       proxy_pass  http://localhost:8081; 
       proxy_redirect off; 

       #Proxy Settings 
       proxy_set_header Host    $host; 
       proxy_set_header X-Real-IP  $remote_addr; 
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
     } 

     # would be a good idea to redirect static assets 
} 

回答

4

我不不喜歡在端口80上運行Java應用程序服務器。需要進程以root身份運行。

最好的方法是安裝Apache(或Nginx)並將nexus配置爲反向代理。有關如何做到這一點我建議你閱讀的Nexus本書的培訓相關部分的詳細信息:

注意

  • 很多其他的優勢,建立一個反向代理。例如,您可以設置一個自定義503錯誤消息,每當您拿下Nexus進行維護時都會顯示該消息。
+0

我也看到了這個http://wiki.ivonet.nl/display/LINUX/Install+or+Upgrade+Sonatype+Nexus –

+0

這個答案已經過時了,因爲一個存在碼頭的世界。現在,非常希望在端口80上的容器中運行應用程序服務器。 –

5

可以使用authbind完成工作(根本沒有任何代理)。因爲nexus是由一個java服務包裝器(jsw)啓動的,而java服務包裝器(jsw)又是由一個啓動腳本啓動的(如果需要,它可以將其自身視爲不同的用戶),因此將它用於nexus有點棘手。

的解決方案如下(相對路徑是相對於Nexus主目錄,$NEXUS_HOME):

  1. conf/nexus.properties設置
application-port=80 
application-host=0.0.0.0

(或任何你需要的)

  1. 爲nexus創建一個(系統)用戶,它有一個登錄shell (!),例如

    adduser --system --shell /bin/sh --no-create-home --group nexus
    (使所有的關係文件屬於新的用戶,例如chown -R nexus:nexus .
    需要一個登錄shell,因爲bin/nexus電話su - $RUN_AS_USER ...,這就是爲什麼用戶nexus必須能夠「登錄」(不是真的)。

  2. 獲得用戶ID爲新用戶:id -u nexus(我們假設它是108

  3. 創建authbind配置文件/etc/authbind/byuid/108(使用Nexus用戶的ID作爲文件名):

0.0.0.0,80 
::,80

IP和端口應該與nexus.properties中使用的相同(請參閱步驟1)。 IPv6端口可能需要也可能不需要,取決於其他配置(來自Jetty)。在authbind中啓用它是安全的。

  • 創建一個小的輔助腳本(所需JSW),放於一個默認的可執行文件路徑(例如/usr/local/bin/authbind-java):
  • #!/bin/sh 
    exec authbind java "[email protected]"

    (使文件可執行文件,通過chmod +x /usr/local/bin/authbind-java

  • 編輯JSW配置文件bin/jsw/conf/wrapper.conf,找到設置wrapper.java.command(應讀java作爲值),並與替換值(剛寫好的幫手腳本)。
  • 現在您已準備好開始連接。從關係的主目錄:

    RUN_AS_USER=nexus bin/nexus start

    (或編輯bin/nexus和直接設置​​並調用bin/nexus start

    的Nexus(Jetty服務器)現在應該開始,初始化和最終綁定到端口80,但仍作爲「無特權」用戶運行nexus


    一個側面說明:因爲你要綁定的端口80用於關係,它可能是一個自己的(虛擬)主機上運行,​​因此它很容易可以到自己的域名指定給它(如nexus.example.com)。這樣做時,我更願意從URI中去掉/nexus前綴(上下文路徑),以保存輸入,它已經在域名中。爲了讓聯繫人在根目錄下服務,請將nexus-webapp-context-path設置爲/(在conf/nexus.properties中)。存儲庫路徑將成爲例如http://nexus.example.com/content/repositories/releases(而不是http://nexus.example.com/nexus/content/repositories/releases)。