Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7974477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:23:08+00:00 2026-06-04T08:23:08+00:00

I need to serve my app through my app server at 8080 , and

  • 0

I need to serve my app through my app server at 8080, and my static files from a directory without touching the app server.

    # app server on port 8080
    # nginx listens on port 8123
    server {
            listen          8123;
            access_log      off;

            location /static/ {
                    # root /var/www/app/static/;
                    alias /var/www/app/static/;
                    autoindex off;
            }


            location / {
                    proxy_pass              http://127.0.0.1:8080;
                    proxy_set_header        Host             $host;
                    proxy_set_header        X-Real-IP        $remote_addr;
                    proxy_set_header        X-Forwarded-For  $proxy_add_x_forwarded_for;
            }
    }

Now, with this config, everything is working fine. Note that the root directive is commented out.

If I activate root and deactivate the alias, it stops working. However, when I remove the trailing /static/ from root, it starts working again.

Can someone explain what’s going on?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T08:23:10+00:00Added an answer on June 4, 2026 at 8:23 am

    There is a very important difference between the root and the alias directives. This difference exists in the way the path specified in the root or the alias is processed.

    root

    • the location part is appended to root part
    • final path = root + location

    alias

    • the location part is replaced by the alias part
    • final path = alias

    To illustrate:

    Let’s say we have the config

    location /static/ {
        root /var/www/app/static/;
        autoindex off;
    }
    

    In this case the final path that Nginx will derive will be

    /var/www/app/static/static
    

    This is going to return 404 since there is no static/ within static/

    This is because the location part is appended to the path specified in the root. Hence, with root, the correct way is

    location /static/ {
        root /var/www/app/;
        autoindex off;
    }
    

    On the other hand, with alias, the location part gets dropped. So for the config

    location /static/ {
        alias /var/www/app/static/;
        autoindex off;           ↑
    }                            |
                                 pay attention to this trailing slash
    

    the final path will correctly be formed as

    /var/www/app/static
    

    In a way this makes sense. The alias just lets you define a new path to represent an existing "real" path. The location part is that new path, and so it gets replaced with the real path. Think of it as a symlink.

    Root, on the other hand is not a new path, it contains some information that has to be collated with some other info to make the final path. And so, the location part is used, not dropped.

    The case for trailing slash in alias

    There is no definitive guideline about whether a trailing slash is mandatory per Nginx documentation, but a common observation by people here and elsewhere seems to indicate that it is.

    A few more places have discussed this, not conclusively though.

    https://serverfault.com/questions/376162/how-can-i-create-a-location-in-nginx-that-works-with-and-without-a-trailing-slas

    https://serverfault.com/questions/375602/why-is-my-nginx-alias-not-working

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Through my ASP.NET / SQL Server 2008 app I need to do a bulk
I'm using Spring/Roo for an app server, and need to be able to post
I need to use the in app purchase server model, where I want the
I need an app that sends an UDP packet to some network server and
We have the rails app, content served from the database. Now we need to
I need to serve static swf using express framework generating dynamic view similar to:
I need to server parts of my application from different domains. To be precise
I need a server to send and recieve XMPP messages from Android clients running
I need to return server time from a webservice. I've got the following code:
I need to know of a solution to run a local test server through

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.