我有一個應用程序是使用angularjs開發的,並且在訪問dist /文件夾時加載整個應用程序。nginx服務於靜態如果沒有發現嘗試反向代理
什麼我試圖待辦事項是,當angularjs,嘗試在反向代理找不到網頁,我試着做下面的設置,但nginx的不允許在單塊
兩次設置相同的位置server {
listen 80;
server_name example.com;
keepalive_timeout 60;
client_max_body_size 10M;
root /var/lib/www/dist;
charset utf-8;
location/{
expires -1;
add_header Pragma "no-cache";
add_header Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
root /var/lib/www/dist;
try_files $uri $uri/ /index.html =404;
}
location/{
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_buffering off;
proxy_http_version 1.1;
proxy_set_header Connection "";
if (!-f $request_filename) {
proxy_pass http://app_root;
break;
}
}
error_page 500 502 503 504 /500.html;
location = /500.html {
root /var/lib/app/etc/templates;
}
}
所以基本上,如果URL 404'ed on angularjs我想它嘗試並將它傳遞給proxy_pass http://app_root;
任何人都可以建議如何實現此設置?
感謝,
UPDATE
所以我想提出的方法,通過「穆罕默德AbuShady」,並更新了nginx的設置下,但仍然沒有工作,而是試圖找到在頁面AngularJS應用程序,而不是移動到@proxy up_stream設置
upstream app_root {
server unix:/tmp/app_root.sock fail_timeout=0;
}
server {
listen 80;
server_name example.com;
keepalive_timeout 60;
client_max_body_size 10M;
root /var/lib/www/dist;
charset utf-8;
location/{
expires -1;
add_header Pragma "no-cache";
add_header Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
root /var/lib/www/dist;
try_files $uri$args $uri$args/ $uri/ /index.html @proxy;
}
location @proxy {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_buffering off;
if (!-f $request_filename) {
proxy_pass http://app_root;
break;
}
}
error_page 500 502 503 504 /500.html;
location = /500.html {
root /var/lib/app/etc/templates;
}
}
那麼當您渲染404頁面時,實際的網址是什麼? – 2015-02-17 23:17:07