{"id":10803,"date":"2021-10-25T22:02:37","date_gmt":"2021-10-25T19:02:37","guid":{"rendered":"https:\/\/kifarunix.com\/?p=10803"},"modified":"2024-03-18T13:25:49","modified_gmt":"2024-03-18T10:25:49","slug":"run-nexus-repository-behind-nginx-reverse-proxy","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/run-nexus-repository-behind-nginx-reverse-proxy\/","title":{"rendered":"Run Nexus Repository Behind Nginx Reverse Proxy"},"content":{"rendered":"\n<p>In this tutorial, you will learn how to run Nexus repository behind <a href=\"https:\/\/docs.nginx.com\/nginx\/admin-guide\/web-server\/reverse-proxy\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Nginx reverse proxy<\/a>. Nginx can be configure to proxy HTTP requests. In this setup, Nginx receives requests and passes it onto <em>specified proxied server, fetches the response, and sends it back to the client<\/em>.<\/p>\n\n\n\n<p>In our previous article, we learnt how to install Nexus repository;<\/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<h2 class=\"wp-block-heading\">Running Nexus Repository Behind Nginx Reverse Proxy<\/h2>\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,&nbsp;<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 to run Nexus repository manager behind Nginx reverse proxy, first configure Nexus to bind it to a loopback interface,&nbsp;<strong><code>127.0.0.1<\/code><\/strong>.<\/p>\n\n\n\n<p>As shown by the&nbsp;<code><strong>ss<\/strong><\/code>&nbsp;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 with the specific server loopback IP address;<\/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 Nginx Web Server<\/h3>\n\n\n\n<p>Next, install Nginx Web server;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apt install nginx -y<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Run Nexus Repository Manager Behind Nginx Reverse Proxy<\/h3>\n\n\n\n<p>Once Nginx Web server is installed, create Nexus site.<\/p>\n\n\n\n<p>Any requests that comes to this site will be forward to the Nexus repository running on the same host and listening on loopback interface.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Create Nginx Nexus Site Configuration<\/h4>\n\n\n\n<p>To create the Nexus site configuration,&nbsp;<code>\/etc\/nginx\/sites-available\/nexus<\/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\/nginx\/sites-available\/nexus << 'EOL'\n  server {\n    listen   *:80 default_server;\n    server_name  nexus.kifarunix-demo.com;\n    access_log \/var\/log\/nginx\/nexus.access.log;\n    error_log \/var\/log\/nginx\/nexus.error.log;\n\n    location \/ {\n      proxy_pass http:\/\/127.0.0.1:8081\/;\n      proxy_set_header Host $host;\n      proxy_set_header X-Real-IP $remote_addr;\n      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n      proxy_buffering    off;\n      proxy_request_buffering off;\n      keepalive_timeout  5 5;\n      tcp_nodelay        on;\n      proxy_connect_timeout 90;\n      proxy_send_timeout 120;\n      proxy_read_timeout 300;\n      client_max_body_size 10m;\n    }\n  }\nEOL\n<\/code><\/pre>\n\n\n\n<p>Verify Nginx Syntax;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nginx -t<\/code><\/pre>\n\n\n\n<p>If the output is, similar to below;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nginx: the configuration file \/etc\/nginx\/nginx.conf syntax is ok\nnginx: configuration file \/etc\/nginx\/nginx.conf test is successful<\/code><\/pre>\n\n\n\n<p>then you are good to proceed. Otherwise fix any errors before you can proceed.<\/p>\n\n\n\n<p>Disable default Nginx site;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>unlink \/etc\/nginx\/sites-enabled\/default\nrm \/etc\/nginx\/sites-available\/default<\/code><\/pre>\n\n\n\n<p>Enable Nginx Nexus site;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ln -s \/etc\/nginx\/sites-available\/nexus \/etc\/nginx\/sites-enabled\/<\/code><\/pre>\n\n\n\n<p>Restart Nginx;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>systemctl restart nginx<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Accessing Nexus running behind Nginx 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\"><img loading=\"lazy\" decoding=\"async\" width=\"1908\" height=\"628\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/10\/nexus-proxied-1.png\" alt=\"Run Nexus Repository Manager Behind Apache Reverse Proxy\" 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<p><a href=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/10\/nexus-proxied-1.png\"><\/a><\/p>\n\n\n\n<p>And that is how easy it is to run Nexus repository manager behind Nginx reverse proxy.<\/p>\n\n\n\n<p>Reference<\/p>\n\n\n\n<p><a href=\"https:\/\/help.sonatype.com\/repomanager3\/installation\/run-behind-a-reverse-proxy#RunBehindaReverseProxy-Example:ReverseProxyonRestrictedPorts\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Nexus 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-manager-behind-apache-reverse-proxy\/\" target=\"_blank\" rel=\"noreferrer noopener\">Run Nexus Repository Manager Behind Apache Reverse Proxy<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, you will learn how to run Nexus repository behind Nginx reverse proxy. Nginx can be configure to proxy HTTP requests. In this<\/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":[3152,4234,4232,229,916,4233,4231],"class_list":["post-10803","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos","tag-nexus","tag-nexus-repository-reverse-proxy","tag-nexus-reverse-proxy","tag-nginx","tag-nginx-reverse-proxy","tag-reverse-proxy","tag-run-nexus-behind-nginx-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\/10803"}],"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=10803"}],"version-history":[{"count":4,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/10803\/revisions"}],"predecessor-version":[{"id":21624,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/10803\/revisions\/21624"}],"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=10803"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=10803"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=10803"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}