title: nginx different locations from totally different folder in filesystem
body: <p>I am currently serving an <em>Application</em> for one domain name using <code>nginx</code>.</p>
  
  <p>I need to serve a completely different <em>Application</em> in a specific <code>location</code>, but that second <em>App</em> is located in a completely different folder in the filesystem.</p>
  
  <p>I understand the differences between <code>root</code> and <code>alias</code> thanks to <a href="https://stackoverflow.com/a/10647080/1920004">this very well explained answer</a> so I opted to use <code>alias</code></p>
  
  <p>The config file looks something like:</p>
  
  <pre><code>server {
    server_name myapp.dev;
    root /home/apps/myapp/build;
    error_log /home/apps/omg-errors.log warn;
    index index.htm index.html;
    error_page 403 404 /404.html;
  
    location /admin {
      alias  /home/apps/admin/;
    }
  }
  </code></pre>
  
  <p>I already tried using <code>root</code>, removing the <code>/admin</code> part at the end of the path pointing to and also tried adding the trailing <code>/</code> at the end of the <code>location</code>, like:</p>
  
  <pre><code>location /admin/ {
    ...
    # also this:
    root /home/apps/;
  }
  </code></pre>
  
  <h2>The important and curious part</h2>
  
  <p>is that the same configuration works pretty well using <code>nginx</code> in my local machine where the config looks like: </p>
  
  <pre><code>server {
    listen 80;
    server_name myapp.local;
    root /Users/lio/Projects/MyApp/my-app-static/build;
    error_log /Users/lio/Projects/MyApp/myapp-error.log warn;
  
    index index.htm index.html;
  
    location /admin {
      alias /Users/lio/Desktop/test-admin;
    }
  }
  </code></pre>
  
  <h3>Logs</h3>
  
  <p>Here are the <code>error-logs</code> catched when trying to access the <code>/admin</code> path:</p>
  
  <pre><code>2020/02/26 04:16:57 [error] 5704#0: *7619 open() "/home/apps/myapp/build/admin" failed (2: No such file or directory), client: xxx.xxx.xxx.xxx, server: myapp.dev, request: "GET /admin HTTP/2.0", host: "myapp.dev"
  </code></pre>
  
  <h3>Environment</h3>
  
  <p>Don't know if could be the fact of different OS and software versions, however here are the details provided by <code>nginx -V</code>:</p>
  
  <p><em>Local</em></p>
  
  <pre><code>nginx version: nginx/1.15.10
  built by clang 10.0.1 (clang-1001.0.46.3)
  built with OpenSSL 1.0.2r  26 Feb 2019
  TLS SNI support enabled
  configure arguments: --prefix=/usr/local/Cellar/nginx/1.15.10 --sbin-path=/usr/local/Cellar/nginx/1.15.10/bin/nginx --with-cc-opt='-I/usr/local/opt/pcre/include -I/usr/local/opt/openssl/include' --with-ld-opt='-L/usr/local/opt/pcre/lib -L/usr/local/opt/openssl/lib' --conf-path=/usr/local/etc/nginx/nginx.conf --pid-path=/usr/local/var/run/nginx.pid --lock-path=/usr/local/var/run/nginx.lock --http-client-body-temp-path=/usr/local/var/run/nginx/client_body_temp --http-proxy-temp-path=/usr/local/var/run/nginx/proxy_temp --http-fastcgi-temp-path=/usr/local/var/run/nginx/fastcgi_temp --http-uwsgi-temp-path=/usr/local/var/run/nginx/uwsgi_temp --http-scgi-temp-path=/usr/local/var/run/nginx/scgi_temp --http-log-path=/usr/local/var/log/nginx/access.log --error-log-path=/usr/local/var/log/nginx/error.log --with-compat --with-debug --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_degradation_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-ipv6 --with-mail --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module
  </code></pre>
  
  <p><em>Server</em></p>
  
  <pre><code>nginx version: nginx/1.14.0
  built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC)
  built with OpenSSL 1.0.2k-fips  26 Jan 2017
  TLS SNI support enabled
  configure arguments: --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module --with-http_perl_module --with-mail --with-mail_ssl_module --with-pcre --with-pcre-jit --with-google_perftools_module --add-module=/builddir/build/BUILD/nginx-1.14.0/passenger-5.3.7/src/nginx_module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --with-ld-opt='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E'
  </code></pre>