【问题标题】:How to run nexus sonatype on port 80?如何在端口 80 上运行 nexus sonatype?
【发布时间】:2012-08-22 02:50:42
【问题描述】:

我有一个 Fedora 服务器。我通过 yum 包管理器安装了 tomcat。然后我在 webapps 文件夹上部署了 nexus 战争。 I tryed using jsvc 在端口 80 上运行服务器并没有工作。我看到你也可以使用port fowarding。最好的选择是什么?

编辑 1:httpd

我从 sonatype doc 关注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>

/home/guillaume/www/nexus/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
}

【问题讨论】:

    标签: tomcat fedora nexus port80


    【解决方案1】:

    可以使用authbind 来完成工作(根本不需要任何代理)。将它用于 nexus 有点棘手,因为 nexus 是由一个 java 服务包装器 (jsw) 启动的,而后者又由一个启动脚本启动(如果需要,它会将自己召回为不同的用户)。

    解决方法如下(相对路径是相对于nexus主目录,$NEXUS_HOME):

    1. conf/nexus.properties设置中
    应用程序端口=80
    应用程序主机=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 中启用它是安全的。

    1. 创建一个小帮助脚本(jsw 需要),放入默认的可执行文件路径(例如/usr/local/bin/authbind-java):
    #!/bin/sh
    exec authbind java "$@"

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

    1. 编辑jsw配置文件bin/jsw/conf/wrapper.conf,找到设置wrapper.java.command(应该读作java作为值)并将值替换为authbind-java(刚刚编写的帮助脚本)。

    现在您已准备好启动 nexus。从nexus的主目录:

    RUN_AS_USER=nexus bin/nexus 启动

    (或编辑bin/nexus并直接设置RUN_AS_USER=nexus并调用bin/nexus start

    Nexus(码头服务器)现在应该启动、初始化并最终绑定到端口 80,但仍以“非特权”用户 nexus 运行。


    附注:由于您正在为 nexus 绑定端口 80,它可能在自己的(虚拟)主机上运行,​​因此可以很容易地为其指定自己的域名(例如 nexus.example.com)。这样做时,我更喜欢从 URI 中去除 /nexus 前缀(上下文路径),以节省输入,它已经在域名中。为了让 nexus 在根目录下服务,请将 nexus-webapp-context-path 设置为 /(在 conf/nexus.properties 中)。例如,存储库路径将变为 http://nexus.example.com/content/repositories/releases(而不是 http://nexus.example.com/nexus/content/repositories/releases)。

    【讨论】:

      【解决方案2】:

      我不喜欢在端口 80 上运行 java 应用服务器。需要以 root 身份运行该进程。

      最好的方法是安装 Apache(或 Nginx)并将 nexus 配置为反向代理。有关如何完成此操作的更多详细信息,我建议阅读 Nexus 书的相关部分:

      注意

      • 设置反向代理还有很多其他优势。例如,您可以设置一个自定义 503 错误消息,每当您关闭 Nexus 进行维护时就会显示该消息。

      【讨论】:

      【解决方案3】:

      使用 iptables 重定向端口怎么样。
      所以nexus仍然在8080端口运行,但是你也可以通过80端口访问。

      iptables -t nat -A PREROUTING -i <interface> -p tcp --dport 80 -j REDIRECT --to-port 8080
      

      有关设置的更多信息,请参阅(例如)https://www.systutorials.com/816/port-forwarding-using-iptables/

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-07-01
        • 2011-08-31
        • 2013-09-13
        • 2011-06-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-02-12
        相关资源
        最近更新 更多