如何为不同的路径配置nginx
how to configure nginx for different paths
我想为 / 上的不同位置配置 nginx,我有以下配置。
server {
listen 80;
server_name bla.com;
location = / { // on exact route match such as 'bla.com'
root /usr/share/nginx/html/folder; // it has index.html
}
location / { // rest all url such as bla.com/* are captured here eg. bla.com/temp/12
root /usr/share/nginx/html/dist; // different folder
}
}
我该怎么做?
我也尝试了以下配置,但没有成功 -
server {
listen 80;
server_name bla.com;
root /usr/share/nginx/html;
location = / {
try_files $uri /folder/index.html; // it has index.html
}
location / { // rest all url such as bla.com/* are captured here eg. bla.com/temp/12
try_files $uri /dist/index.html; // different folder
}
}
您可以通过创建如下内容来实现此目的:
server {
index index.html index.htm;
server_name test.example.com;
location / {
root /var/www/website1/public_html;
}
location /temp {
root /var/www/website2/public_html;
}
}
您也可以像这样对单个文件执行此操作:
location /robots.txt {
alias /var/www/website/public_html/robots.txt;
}
我想为 / 上的不同位置配置 nginx,我有以下配置。
server {
listen 80;
server_name bla.com;
location = / { // on exact route match such as 'bla.com'
root /usr/share/nginx/html/folder; // it has index.html
}
location / { // rest all url such as bla.com/* are captured here eg. bla.com/temp/12
root /usr/share/nginx/html/dist; // different folder
}
}
我该怎么做?
我也尝试了以下配置,但没有成功 -
server {
listen 80;
server_name bla.com;
root /usr/share/nginx/html;
location = / {
try_files $uri /folder/index.html; // it has index.html
}
location / { // rest all url such as bla.com/* are captured here eg. bla.com/temp/12
try_files $uri /dist/index.html; // different folder
}
}
您可以通过创建如下内容来实现此目的:
server {
index index.html index.htm;
server_name test.example.com;
location / {
root /var/www/website1/public_html;
}
location /temp {
root /var/www/website2/public_html;
}
}
您也可以像这样对单个文件执行此操作:
location /robots.txt {
alias /var/www/website/public_html/robots.txt;
}