Не могу использовать несколько проектов - PullRequest
0 голосов
/ 23 ноября 2018

Я пытаюсь настроить свой nginx для использования нескольких проектов по пути.

Поэтому у меня есть клиентская сторона на основе javascript (проект VueJs), которая отправляет запрос в api.Корни API начинаются с /api (Laravel Project).У меня также есть админ-панель на основе Laravel.URL админ панели будет начинаться с /admin.

Вот мой nginx файл конфигурации

server {
    server_name cabinet.mydomain.org; 

   # auth_basic "Restricted Content";
   # auth_basic_user_file /etc/nginx/.htpasswd;

   # access_log /var/www/cabinet/access.log;
   # error_log /var/www/cabinet/error.log;

    root /var/www/cabinet/api/html/public;

    # Add index.php to the list if you are using PHP
    index index.php index.html index.htm;

    #location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
    #   try_files $uri $uri/ =404;
    #}

    location /api {
          access_log /var/log/cabinet.api.acc.log;
          error_log /var/www/cabinet.api.error.log debug;
          try_files $uri $uri /index.php$args;
        }

        location /admin {
          access_log /var/log/cabinet.admin.acc.log;
          error_log /var/www/cabinet.admin.error.log debug;
      root /var/www/cabinet-admin/public;
          try_files $uri $uri /index.php$args;
        }



        location / {
          try_files $uri $uri/ /index.html;
          root /var/www/cabinet/client/dist;
        }

    location = / {
          return 301 $scheme://$server_name/login/;
        }


#        location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
#       return 500; 
           # Some basic cache-control for static files to be sent to the browser
#           expires max;
#           add_header Pragma public;
#           add_header Cache-Control "public, must-revalidate, proxy-revalidate";
#       }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #

    location ~ \.php$ {
       include snippets/fastcgi-php.conf;
       fastcgi_pass unix:/run/php/php7.2-fpm.sock;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #   deny all;
    #}

 # managed by Certbot

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/cabinet.mydomain.org-0001/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/cabinet.mydomain.org-0001/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

server {
    if ($host = cabinet.mydomain.org) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    #if ($host = cabinet.mydomain.com) {
    #    return 301 https://cabinet.mydomain.org$request_uri;
    #} # managed by Certbot

    #if ($host = cabinet.mydomain.org) {
    #    return 301 https://$host$request_uri;
    #} # managed by Certbot

    server_name cabinet.mydomain.org cabinet.mydomain.com;
    listen 80;
    return 301 https://cabinet.mydomain.org$request_uri;
    return 404; # managed by Certbot


}

Так что при попытке посетить /admin сервер перенаправляется на /login.

Пожалуйста, помогите решить эту проблему

1 Ответ

0 голосов
/ 23 ноября 2018

Попробуйте это.

server {
    server_name cabinet.mydomain.org; 

   # auth_basic "Restricted Content";
   # auth_basic_user_file /etc/nginx/.htpasswd;

   # access_log /var/www/cabinet/access.log;
   # error_log /var/www/cabinet/error.log;

    root /var/www;

    # Add index.php to the list if you are using PHP
    index index.php index.html index.htm;

    #location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
    #   try_files $uri $uri/ =404;
    #}

    location /api {
          access_log /var/log/cabinet.api.acc.log;
          error_log /var/www/cabinet.api.error.log debug;
          root PATH_TO_YOUR_PROJECT;
          try_files $uri $uri /PATH_TO_PROJECT/index.php$args;
        }

        location /admin {
          access_log /var/log/cabinet.admin.acc.log;
          error_log /var/www/cabinet.admin.error.log debug;
          root /var/www/cabinet-admin/public;
          try_files $uri $uri /cabinet-admin/public/index.php$args;
        }

Пожалуйста, следуйте документам, связанным с

$ try_files

root

...