Reputation: 7502
I have the following content in my nginx.conf
and everything else is as is
server {
listen 8081;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
#location / {
#root html;
#index index.html index.htm;
#}
location = /console {
proxy_pass http://localhost:7001/main/console;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
auth_basic "Admin Area";
auth_basic_user_file /etc/apache2/.htpasswd;
}
}
Now when I launch http://localhost:8081/console
it successfully launches the webpage and even asks me for password.
But there are some static content in this location /main/resources/org/nett/main/images/jquery-3.1.1.min.js
When I click on this it throws 404
. What should be in my nginx.conf
to serve the static content inside /main/resources/org/nett/main/images/
folder?
Upvotes: 0
Views: 71
Reputation: 16304
You'll note that the location of the static content, /main/resources...
, doesn't match any of your locations. . resources
is not under /main/console
, and therefore there's no way to access it under your existing proxy-pass
location.
Reconsider whether you need to change the path of your proxy. It can be done, but requires additional configuration. If you merely redirect /
to 7001:/
, then when the data at /main/console
refers to /main/resources
, that will also have a valid proxy path through nginx.
If your definition of 'working' means the /console
maps to 7001/main/console
, you'll have to expand upon that definition to address also how you want to map requests under /main/<anythingelse>
, more of which may have yet to be uncovered. You'll also have to handle rewriting the references to itself the application sends back ( if, for example, more is requested from /main/console
, it will have the same problem as stuff under /main/resources
, because it, too, doesn't match /console
. URL rewrites at the proxy should only be undertaken with a decent grasp of regular expressions and http, and only with a sincere and practiced willingness to RTFM. its complicated.
By the by, if you're attempting to add basic auth to whatever's on 7001
, make sure to also encrypt your connection (HTTPS), otherwise your credentials are plaintext on the network (http://mark-kirby.co.uk/2013/how-to-authenticate-apis-http-basic-vs-http-digest/).
Upvotes: 1