Как правильно использовать nginx try_files в proxy_pass? - PullRequest
0 голосов
/ 29 июня 2019

Я пытаюсь использовать try_files в nginx proxy_pass.Если я наберу h - p: //example.com/admin1/SisrAZbCCnisI и не использую try_fiels, то все работает.

  • [INFO] dart: GET / admin1 / SisrAZbCCnisI = 9 мс 200
  • [INFO] dart: GET / admin1 / SisrAZbCCnisI = 63 мс 200

Если я введу неправильный URL, то получу ошибку 404.

  • [INFO] dart: GET / admin1 12ms 404
  • [INFO] dart: GET / admin1 / 12ms 404
  • [INFO] dart: GET / admin1 / неправильная строка 12 мс 404

и когда я пытаюсь использовать try_files всегда, я получаю и по умолчанию index.html.

Как правильноиспользовать nginx try_files в proxy_pass?

ОБНОВЛЕНИЕ: Страница ошибки и index.html работает.Только мой proxy_pass не работает.все еще показывает index.default, когда я печатаю / adnin1 / ***

add_header X-Frame-Options SAMEORIGIN;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";

server {
    charset UTF-8;
    listen 80;
    listen [::]:80;
    server_name  my.example.com;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    # redirect error pages to the static page
    error_page 401 402 403 405 404  /index.html;
    location = /index.html {
        root /usr/share/nginx/html;
        internal;
    }

    # redirect server error pages to the static page
    error_page   500 502 503 504  /index.html;
    location = /index.htm {
        root /usr/share/nginx/html;
        internal;
    }

    # deny access to .htaccess files
    location ~ /\.ht {
        deny  all;
    }

    # Deny access to hidden files (beginning with a period)
    location ~ /\. {
         deny all;
    }

   if ($host = my.example.com/admin1) {
         return 301 https://my.example.com$request_uri;
   }

   if ($host = my.example.com/admin2) {
         return 301 https://my.example.com$request_uri;
   }

}

server {
    charset UTF-8;
    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl http2; # managed by Certbot
    server_name  my.example.com;

    ssl_certificate /etc/letsencrypt/live/my.example.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/my.example.com/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

    access_log  /var/log/nginx/host.access.log  main;

    # redirect mobile app to
    location /admin1 {
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $http_host;
        proxy_pass "http://127.0.0.1:3000";
        proxy_connect_timeout 1;
        proxy_next_upstream error timeout http_500 http_502 http_503 http_504 http_404;
        proxy_intercept_errors on;
    }

    # redirect mobile app to
    location /admin2 {
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $http_host;
        proxy_pass "http://127.0.0.1:3000";
        proxy_connect_timeout 1;
        proxy_next_upstream error timeout http_500 http_502 http_503 http_504 http_404;
        proxy_intercept_errors on;
    }

    # redirect error pages to the static page
    error_page 401 402 403 405 404  /index.html;
    location = /index.html {
        root /usr/share/nginx/html;
        internal;
    }

    # redirect server error pages to the static page
    error_page   500 502 503 504  /index.html;
    location = /index.htm {
        root /usr/share/nginx/html;
        internal;
    }

    # deny access to .htaccess files
    location ~ /\.ht {
        deny  all;
    }

    # Deny access to hidden files (beginning with a period)
    location ~ /\. {
         deny all;
    }

    if ($request_method !~ ^(GET|HEAD|POST)$ )
    {
    return 404;
    } 

}
...