nginx single page js app pushstate vs wordpress rewrite rules

, я хотел бы добавить: Подпапка / client, содержащая базовое js-приложение (с pushstate) Подпапка / admin, содержащая приложение backbone js (с pushstate или без него)

И когда я открываю свой http://example.dev/client в браузере, он действительно открывает index.html сингла page, но как только я добавляю / gallery / 1 / date к URL-адресу, открывается страница wordpress 404 вместо pushstate.

Это мой блок местоположений nginx:

# {{ ansible_managed }}

location ^~ /admin {
    #alias /var/www/project/admin/public/;
    try_files $uri $uri/ /index.html;
    rewrite ^/admin/(.+/)$ /admin/index.html last;
}

location ^~ /client {
    #alias /var/www/project/client/public/;
    try_files $uri $uri/ /index.html;
    rewrite ^/client/(.+/)$ /client/index.html last;
}

# Prevent PHP scripts from being executed inside the uploads folder.
location ~* /app/uploads/.*\.php$ {
    deny all;
}

location / {
   try_files $uri $uri/ /index.php?$args;
}

# Set the max body size equal to PHP's max POST size.
client_max_body_size {{ php_post_max_size | default('25m') | lower }};

include h5bp/directive-only/x-ua-compatible.conf;
include h5bp/directive-only/extra-security.conf;
include h5bp/location/cross-domain-fonts.conf;
include h5bp/location/protect-system-files.conf;

Изменить: это весь блок сервера: (include wordpress.conf содержит пример кода выше)

    # Ansible managed: /home/ivan/Dev/fapps/trellis/roles/wordpress-setup/templates/wordpress-site.conf.j2 modified on 2016-02-27 10:16:10 by ivan on ivan-ubuntu

server {
    listen 443 ssl http2;

  server_name   fapps.dev  ;
  access_log   /srv/www/example.com/logs/access.log;
  error_log    /srv/www/example.com/logs/error.log;

  root  /srv/www/example.com/current/web;
  index index.php index.htm index.html;

  charset utf-8;

  # See Virtualbox section at http://wiki.nginx.org/Pitfalls
  sendfile off;

  add_header Fastcgi-Cache $upstream_cache_status;

      include h5bp/directive-only/ssl.conf;
    include h5bp/directive-only/ssl-stapling.conf;

    ssl_dhparam /etc/nginx/ssl/dhparams.pem;
    ssl_buffer_size 1400; # 1400 bytes to fit in one MTU

                add_header Strict-Transport-Security "max-age=31536000; includeSubdomains; preload";

    ssl_certificate         /etc/nginx/ssl/example.com_self_signed.pem;
      ssl_trusted_certificate /etc/nginx/ssl/example.com_self_signed.pem;
      ssl_certificate_key     /etc/nginx/ssl/example.com_self_signed.key;

  include includes.d/example.com/*.conf;
  include wordpress.conf;

  location ~ \.php$ {
    try_files $uri =404;
    error_page 404 /index.php;

    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
    fastcgi_param DOCUMENT_ROOT $realpath_root;
    fastcgi_pass unix:/var/run/php-fpm-wordpress.sock;
  }
}

server {
  listen 80;
  server_name fapps.dev www.fapps.dev;
  return 301 https://$host$request_uri;
}

server {
  listen 443 ssl http2;
  server_name www.fapps.dev;
  return 301 $scheme://fapps.dev$request_uri;
}
2
задан 28 February 2016 в 09:41
1 ответ

Последний элемент в вашей директиве try_files должен быть URI приложения ( /admin/index.html и /client/index.html соответственно).

Фактически, перезаписывают вероятно, является избыточным.

Попробуйте:

location ^~ /admin {
    try_files $uri $uri/ /admin/index.html;
}
location ^~ /client {
    try_files $uri $uri/ /client/index.html;
}

Подробнее см. этот документ .

0
ответ дан 3 December 2019 в 14:30

Теги

Похожие вопросы