2014-12-03 30 views
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; 
} 
+0

試試這個http://stackoverflow.com/questions/12924896/rewrite-all-requests-to-index-php-with-nginx – raam86 2014-12-03 21:00:22

+0

我試過一個非常類似的答案已經引用了@rewrite規則,但沒有運氣的帽子。不知道重寫規則是否正確,但... – 2014-12-03 21:10:25

回答

1

原來,問題的根源是,咕嚕沒有應用基礎/樣式聲明之前,即使我有

<base href="/"> 

集的我的index.html頭部

解決方案是一個簡單的...只需將底部標記移動到頭部的頂部而不是底部!

相關問題