{"id":10801,"date":"2021-10-24T10:30:58","date_gmt":"2021-10-24T07:30:58","guid":{"rendered":"https:\/\/kifarunix.com\/?p=10801"},"modified":"2024-03-18T13:26:49","modified_gmt":"2024-03-18T10:26:49","slug":"run-nexus-repository-manager-behind-apache-reverse-proxy","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/run-nexus-repository-manager-behind-apache-reverse-proxy\/","title":{"rendered":"Run Nexus Repository Manager Behind Apache Reverse Proxy"},"content":{"rendered":"\n<p>Follow through this tutorial to learn how to run Nexus repository manager behind Apache reverse proxy. According <a href=\"https:\/\/httpd.apache.org\/docs\/2.4\/howto\/reverse_proxy.html\" target=\"_blank\" rel=\"noreferrer noopener\">Reverse proxy guide page<\/a>, <em>Apache, apart from functioning as a &#8220;basic&#8221; web server, and providing static and dynamic content to end-users, it ca also act as a reverse proxy server, also-known-as a &#8220;gateway&#8221; server<\/em>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Running Nexus Repository Manager Behind Apache Reverse Proxy<\/h2>\n\n\n\n<p>In our previous tutorial, we learnt how to install Nexus repository manager;<\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-nexus-repository-manager-on-debian-11\/\" target=\"_blank\" rel=\"noreferrer noopener\">Install Nexus Repository Manager on Debian 11<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-nexus-repository-manager-on-ubuntu\/\" target=\"_blank\" rel=\"noreferrer noopener\">Install Nexus Repository Manager on Ubuntu 20.04<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-nexus-repository-manager-on-debian\/\" target=\"_blank\" rel=\"noreferrer noopener\">Install Nexus Repository Manager on Debian 10<\/a><\/p>\n\n\n\n<p>In all the above tutorials, Nexus port 8081 is exposed to the external networks as can be seen on Nexus URL, <strong><code>http:\/\/server-IP:8081<\/code><\/strong>.<\/p>\n\n\n\n<p>When you run Nexus repository behind a reverse proxy, you can access it without having to specify its port on the URL.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Bind Nexus Repository to Localhost Interface<\/h3>\n\n\n\n<p>NOTE: if your Nexus instance is already listening on a loopback address, then skip this step.<\/p>\n\n\n\n<p>When you check, by default, at least in the guides above, Nexus is not bound to specific interface on a server on which it is running and hence listens on all interfaces on port 8081.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ss -altnp | grep 8081<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>LISTEN 0      50           0.0.0.0:8081       0.0.0.0:*    users:((\"java\",pid=663,fd=691))<\/code><\/pre>\n\n\n\n<p>Before you can proceed, first configure Nexus to bind it to a loopback interface, <strong><code>127.0.0.1<\/code><\/strong>.<\/p>\n\n\n\n<p>As shown by the <code><strong>ss<\/strong><\/code> command output above, Nexus listens on all interfaces on port 8081\/tcp.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>grep application- \/opt\/nexus\/etc\/nexus-default.properties<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>application-port=8081\napplication-host=0.0.0.0<\/strong><\/code><\/pre>\n\n\n\n<p>To bind Nexus to localhost interface, replace the 0.0.0.0 address in the configuration file above;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sed -i 's\/0.0.0.0\/127.0.0.1\/' \/opt\/nexus\/etc\/nexus-default.properties<\/code><\/pre>\n\n\n\n<p>Once you have made the changes, restart Nexus;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>systemctl restart nexus<\/code><\/pre>\n\n\n\n<p>Once Nexus starts, you can confirm the address it is bind to again;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ss -altnp | grep 8081<\/code><\/pre>\n\n\n\n<p>Sample output;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>LISTEN 0      50         127.0.0.1:8081       0.0.0.0:*    users:((\"java\",pid=2711,fd=699))<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Install Apache Web Server<\/h3>\n\n\n\n<p>Next, install Apache Web server;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apt install apache2 -y<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Running Nexus Repository Manager Behind Apache Reverse Proxy<\/h3>\n\n\n\n<p>Once Apache Web server is installed, create Nexus site. Any requests that comes to this site will be forward to the Nexus repository running on the same host on loopback interface.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Create Apache Nexus Site Configuration<\/h4>\n\n\n\n<p>To create the Nexus site configuration, <code>\/etc\/apache2\/sites-available\/nexus.conf<\/code>, you can simply copy and paste the content below on the terminal.<\/p>\n\n\n\n<p><strong>Replace the names of the site accordingly.<\/strong><\/p>\n\n\n\n<pre class=\"scroll-box\"><code>\ncat > \/etc\/apache2\/sites-available\/nexus.conf<< 'EOL'\nProxyRequests Off\nProxyPreserveHost On\n  \n<VirtualHost *:80>\n  ServerName nexus.kifarunix-demo.com\n  ServerAdmin admin@kifarunix-demo.com\n\n  AllowEncodedSlashes NoDecode\n\n  ProxyPass \/ http:\/\/localhost:8081\/ nocanon\n  ProxyPassReverse \/ http:\/\/localhost:8081\/\n  ErrorLog ${APACHE_LOG_DIR}\/nexus.error.log\n  CustomLog ${APACHE_LOG_DIR}\/nexus.access.log common\n<\/VirtualHost>\nEOL\n<\/code><\/pre>\n\n\n\n<p>Verify Apache Syntax;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apachectl -t<\/code><\/pre>\n\n\n\n<p>If the output is, Syntax OK, then you are good to proceed. Otherwise fix any would be errors before you can proceed.<\/p>\n\n\n\n<p>Disable default Apache site;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>a2dissite 000-default.conf<\/code><\/pre>\n\n\n\n<p>Enable Apache Nexus site;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>a2ensite nexus.conf<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Enable Apache Proxy Modules<\/h4>\n\n\n\n<p>Next, you need to enable required Apache proxy modules (<code>mod_proxy<\/code> and <code>mod_proxy_http<\/code>).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>a2enmod proxy proxy_http<\/code><\/pre>\n\n\n\n<p>Restart Apache Web server;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>systemctl restart apache2<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Accessing Nexus running behind Apache Proxy<\/h3>\n\n\n\n<p>You can now access your Nexus without specifying the port on the url.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1908\" height=\"628\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/10\/nexus-proxied-1.png\" alt=\"\" class=\"wp-image-10811\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/10\/nexus-proxied-1.png?v=1635060438 1908w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/10\/nexus-proxied-1-768x253.png?v=1635060438 768w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/10\/nexus-proxied-1-1536x506.png?v=1635060438 1536w\" sizes=\"(max-width: 1908px) 100vw, 1908px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Reference<\/h3>\n\n\n\n<p><a href=\"https:\/\/help.sonatype.com\/repomanager3\/installation\/run-behind-a-reverse-proxy\" rel=\"nofollow noopener\" target=\"_blank\">Run Behind a Reverse Proxy<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Other Tutorials<\/h3>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/run-nexus-repository-behind-nginx-reverse-proxy\/\" target=\"_blank\" rel=\"noreferrer noopener\">Run Nexus Repository Behind Nginx Reverse Proxy<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-and-setup-jenkins-on-ubuntu\/\" target=\"_blank\" rel=\"noreferrer noopener\">Install and Setup Jenkins on Ubuntu 20.04<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-sonarqube-on-ubuntu\/\" target=\"_blank\" rel=\"noreferrer noopener\">Install SonarQube on Ubuntu 20.04<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Follow through this tutorial to learn how to run Nexus repository manager behind Apache reverse proxy. According Reverse proxy guide page, Apache, apart from functioning<\/p>\n","protected":false},"author":3,"featured_media":10799,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[121],"tags":[4226,3152,4223,4225,4224],"class_list":["post-10801","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos","tag-apache-reverse-proxy","tag-nexus","tag-nexus-repository-manager-apache-proxy","tag-run-nexus-behind-a-reverse-proxy","tag-run-nexus-repository-manager-behind-apache-reverse-proxy","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50","resize-featured-image"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/10801"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=10801"}],"version-history":[{"count":7,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/10801\/revisions"}],"predecessor-version":[{"id":21626,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/10801\/revisions\/21626"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/10799"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=10801"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=10801"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=10801"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}