试图使用带有Laravel后端的角JS从Apache移动到Nginx。
前端和后端完全相互独立,如var/www/角钢和var/www/laravel。它们来自相同的域--通过mysite.com/api获得的mysite.com (角)和laravel路由。
我已经完成了所有工作,包括mysite.com/foo这样的前端路由的html5mode和浏览器刷新。
问题是,刷新或手动输入mysite.com/foo/bar不起作用。相反,html是在没有css的情况下提供的,这意味着它不会被路由到角。
任何建议都是非常感谢的。
下面是我当前的Nginx配置:
server {
listen 80 default_server;
server_name default;
root /home/forge/default/laravel/public;
# FORGE SSL (DO NOT REMOVE!)
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
# ssl_certificate;
# ssl_certificate_key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
index index.html index.htm index.php;
charset utf-8;
location / {
root /home/forge/default/angular/dist;
try_files $uri $uri/ /index.html;
}
location /lvl/ {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \/lvl\/index\.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
include fastcgi.conf;
#This specifically sets so the /api/ portion
#of the URL is not included
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
fastcgi_param PATH_INFO $fastcgi_path_info;
#fastcgi_param ENV production;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/default-error.log error;
error_page 404 /index.html;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
编辑1: 86的评论我尝试了一个版本的重写,他给我提供了相同的确切结果,问题仍然存在。这是我做的编辑:
location / {
root /home/forge/default/angular/dist;
try_files = $uri @missing;
}
location @missing {
rewrite ^/$ /index.html last;
}
发布于 2014-12-04 04:58:15
问题的根源在于,尽管我有
<base href="/">
设置在我的index.html的头上
解决方案很简单..。只需将基本标签移动到头部部分的顶部,而不是底部!
https://stackoverflow.com/questions/27281388
复制相似问题