所以我對此還很陌生,我有一個 nginx 伺服器並運行一個簡單的網頁。我的配置sites-available
是:
server {
listen 80 default_server;
root /var/www/mywebsite/;
index /html/index.html;
server_name mywebsite.com www.mywebsite.com;
location / {
try_files $uri $uri/ =404;
}
}
我的index.html位於這個結構中:
+------+ +----------+
+ html +-->+index.html|
+------+ +----------+
|
| +--------------+
+-->+scnd_page.html|
+--------------+
當我訪問時mywebsite.com
,我看到了index.html
。我怎樣才能mywebsite.com/scnd_page/
指向send_page.html
?
我嘗試過一些創作
location /scnd_page {
}
但我不確定我是否走在正確的軌道上。這甚至要在這個文件上完成嗎?
答案1
答案2
您可以只在 location 區塊內配置索引參數:
location /html/scnd_page { index scnd_page.html; }
您也可以將 scnd_page.html 全域定義為「輔助」索引:
server {
listen 80 default_server;
root /var/www/mywebsite/;
# carefull setting '/html/index.html'...
index index.html scnd_page.html;
server_name mywebsite.com www.mywebsite.com;
location / {
try_files $uri $uri/ =404;
}
}