我有一個檔案結構,看起來像這樣的
demo
| 構建
| 影像
| |- logo.png
| | static
| css
| |- style.css
| | js
| |- index.html
| 控制器
| api
|- users.php
這是一張我想設定我的apache vhosts的地圖。
- 所有的正常路徑都需要重定向到
build/index.html。
- 資源路徑(以
.*結尾)需要重定向到build/**并保留檔案路徑 。
- API(以
/api/**開頭)需要重定向到controllers/api/**。
| url | 路徑 |
|---|---|
https://demo.com/ |
build/index.html | 。
https://demo.com/users | build/index.html | https://demo.com/users/16 | build/index.html | https://demo.com/images/logo.png |
build/images/logo.png | build/images/logo.png |
https://demo.com/static/css/style.css |
build/static/css/style.css | build/static/css/style.css |
https://demo.com/api/users | controller/css.css |
controllers/api/users | controllers/api/users |
編輯經過大量的嘗試,我創建了這樣的apache vhost,而且還有點效果。這是正確的方法嗎?我對服務器端沒有什么經驗。
現在我必須用nginx實作同樣的功能,因為我的真實服務器使用的是nginx。我如何用nginx設定做同樣的事情?
<VirtualHost *:80>
DocumentRoot "/Users/hao/Projects/demo"
服務器名稱 demo.dev
選項 FollowSymLinks
重寫引擎開啟
RewriteRule ^(?!/?api/)(.*.w )$ /build/$1 [L)
RewriteRule ^(?!/?api/|/?$) /build/index.html [L]
RewriteRule ^/?api/(.*)$ /controllers/api/$1 [QSA,NE,L]
</VirtualHost>
uj5u.com熱心網友回復:
看起來你可以直接使用/Users/hao/Projects/demo/build作為你的根。假設你在/Users/hao/Projects/demo/controllers/api目錄下只有PHP檔案,你可以嘗試以下的配置:
server {
server_name demo.dev;
root /Users/hao/Projects/demo/build;
index index.html。
location / {
try_files $uri /index.html。
}
location ~ ^/api/. .php$ {
root /Users/hao/Projects/demo/controllers;
try_files $uri =404;
包括 fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass <套接字路徑或ip:埠到PHP-FPM守護程式這里>。
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/309788.html
標籤:
下一篇:洗掉已發現的資料
