2

I'm having difficulties configuring reverse proxy to bring user from http://localhost/nexus/ to http://localhost:8081/.

My current nginx.conf looks like this:-

worker_processes 4;

events { 
    worker_connections 1024; 
}

http {
    server {
        listen 80;

        location /nexus/ {
            proxy_pass         http://localhost:8081/;

            proxy_redirect          off;
            proxy_set_header        Host            $host;
            proxy_set_header        X-Real-IP       $remote_addr;
            proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    }
}

When I hit http://localhost/nexus/, it partially renders the page.

When I inspected the HTML source code, I noticed the javascript links, image links and stylesheet links are not constructed properly.

For example, I'm seeing this:-

<link rel="stylesheet" type="text/css" href="http://localhost/static/rapture/resources/loading-prod.css?_v=3.3.1-01">
<script type="text/javascript" src="http://localhost/static/rapture/baseapp-prod.js?_v=3.3.1-01"></script>
<img id="loading-logo" src="http://localhost/static/rapture/resources/images/loading-logo.png?_v=3.3.1-01"/>

... but, it should be this:-

<link rel="stylesheet" type="text/css" href="http://localhost/nexus/static/rapture/resources/loading-prod.css?_v=3.3.1-01">
<script type="text/javascript" src="http://localhost/nexus/static/rapture/baseapp-prod.js?_v=3.3.1-01"></script>
<img id="loading-logo" src="http://localhost/nexus/static/rapture/resources/images/loading-logo.png?_v=3.3.1-01"/>

How should my nginx.conf look to get the rest of the page rendered properly?

Thank you very much.

2
  • If you need to change URL in generated HTML you need to change your application which generates this HTML. Otherwise you can configure ngingx to serve static files directly with 'location /static' pointing to your static files directory.
    – AlexD
    May 29 '17 at 21:57
  • 1
    I can't change the generated HTML because it's a different web software by itself.
    – limc
    May 29 '17 at 22:04
1

You need to configure your nginx to serve static files directly:

location /static {
  root /path/to/static/files;
}

The nginx process will need read permission to all files in the static sub-tree and to its parent directories.

4
  • While it works, it is causing a problem because I have other web software running on the different base path and it too is also use /static for their asset files.
    – limc
    May 30 '17 at 1:22
  • Then I recommend to look at your application again and find a way to tell it that it is running with prefix /nexus, so it generates correct URLs.
    – AlexD
    May 30 '17 at 2:03
  • Actually, you can try changing proxy_pass to 127.0.0.1:8081/nexus - it is possible that application detects its base URL automatically
    – AlexD
    May 30 '17 at 2:11
  • You are absolutely right. I configured Nexus to have a custom context path and change the proxy_pass to match that ( http://localhost:8081/nexus )... and it works. Thank you very much for your help.
    – limc
    May 30 '17 at 12:42
0

I got the same error and resolved it:

  1. change contex root from "/" to "/nexus" in nexus/conf/nexus-default.properties and resart
  2. change the url in nginx accordingly and restart

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.