PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, September 2, 2022

[FIXED] What should my nginx.conf look like for serving static content

 September 02, 2022     nginx, nginx-reverse-proxy     No comments   

Issue

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?


Solution

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/).



Answered By - Daniel Farrell
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing