我有一个软呢帽服务器。我通过 yum 包管理器安装了 tomcat。然后我在 webapps 文件夹上部署了 nexus war。 I tryed using jsvc在端口 80 上运行服务器并没有工作。我看到你也可以使用 port fowarding .什么是最佳选择?
编辑 1:httpd
我关注了3.8. Running Nexus Behind a Proxy来自sonatype doc,我有点困惑。 我安装了 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:::* 收听 3965/httpd
tcp 0 0:::8081:::* 听 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
}
最佳答案
可以使用 authbind完成工作(根本没有任何代理)。不过,将它用于 nexus 有点棘手,因为 nexus 是由 java 服务包装器 (jsw) 启动的,而后者又由启动脚本启动(如果需要,它会将自己召回为不同的用户)。
解决方法如下(相对路径是相对于nexus家目录,$NEXUS_HOME
):
- 在
conf/nexus.properties
中设置
application-port=80 application-host=0.0.0.0
(或任何你需要的)
为 nexus 创建一个(系统)用户,它有一个登录 shell(!),例如
adduser --system --shell /bin/sh --no-create-home --group nexus
(让所有的 nexus 文件都属于新用户,例如chown -R nexus:nexus .
)
需要登录 shell,因为bin/nexus
调用su - $RUN_AS_USER ...
,这就是为什么用户nexus
必须能够“登录”(不是真的)。获取新用户的用户 ID:
id -u nexus
(假设它是108
)创建 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 "$@"
(通过 chmod +x/usr/local/bin/authbind-java
使文件可执行)
- 编辑jsw配置文件
bin/jsw/conf/wrapper.conf
,找到设置wrapper.java.command
(应该是java
作为值)并将值替换为authbind-java
(刚刚编写的帮助脚本)。
现在您已准备好启动 nexus。来自 nexus 的主目录:
RUN_AS_USER=nexus bin/nexus start
(或直接编辑bin/nexus
,设置RUN_AS_USER=nexus
,调用bin/nexus start
)
Nexus(码头服务器)现在应该启动、初始化并最终绑定(bind)到端口 80,但仍以“非特权”用户 nexus
运行。
旁注:由于您正在为 nexus 绑定(bind)端口 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/发布
).
关于tomcat - 如何在端口 80 上运行 nexus sonatype?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12144987/