nginx разных мест из совершенно другой папки в файловой системе - PullRequest
0 голосов
/ 26 февраля 2020

В настоящее время я подаю Приложение для одного доменного имени, используя nginx.

Мне нужно подать совершенно другое Приложение в заданном c location, но это второе приложение находится в совершенно другой папке в файловой системе.

Я понимаю разницу между root и alias благодаря , это очень хорошо объясненный ответ , поэтому я решил использовать alias

Файл конфигурации выглядит примерно так:

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/;
  }
}

Я уже пытался использовать root, удаляя часть /admin в конце пути, указывающего, а также попытался добавить конечный / в конце location, например:

location /admin/ {
  ...
  # also this:
  root /home/apps/;
}

Важная и любопытная часть

заключается в том, что та же конфигурация работает довольно хорошо, используя nginx на моей локальной машине, где конфигурация выглядит так:

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;
  }
}

Журналы

Вот error-logs, перехваченные при попытке доступа к /admin путь:

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"

Окружающая среда

Не знаю, может быть фактом различных версий ОС и программного обеспечения, однако вот подробности, предоставленные nginx -V:

Локальный

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

Сервер

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'

1 Ответ

0 голосов
/ 26 февраля 2020

В вашем втором фрагменте вы также должны предоставить папку / admin, как указано ниже:

location /admin/ {
  ...
  # also this:
  root /home/apps/admin;
}

В противном случае, чтобы получить доступ к области администратора, вам нужно будет ввести yourdomain.tld / admin / admin (как последнее / admin) - это пропущенный /admin в вашей root /home/apps декларации.

Достаточно ли этого для вас?

...