0
尝试使用带有Laravel后端的Angular JS从Apache移植到Nginx。Angular-Nginx将domain/foo改写为角根,而不是domain/foo/bar
的前端和后端是完全相互独立的,如在无功/网络/角和无功/网络/ laravel。它们是由同一个域提供 - 通过mysite.com/api
我就拥有了一切工作,包括对前端的路线一样html5mode和浏览器刷新mysite.com(角)和laravel API获得航线mysite.com/foo
的问题是,刷新或手动输入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: 每raam86的评论我想一个版本,他下文称我与同一个确切的结果重写的,问题仍然存在。下面是我所做的编辑:
location/{
root /home/forge/default/angular/dist;
try_files = $uri @missing;
}
location @missing {
rewrite ^/$ /index.html last;
}
试试这个http://stackoverflow.com/questions/12924896/rewrite-all-requests-to-index-php-with-nginx – raam86 2014-12-03 21:00:22
我试过一个非常类似的答案已经引用了@rewrite规则,但没有运气的帽子。不知道重写规则是否正确,但... – 2014-12-03 21:10:25