我有安装nginx的Ubuntu服务器16.04服务器(nginx / 1.10.3)
我只有一个DNS名称energy.mysite.local
我需要将其用于多个网站。
我有2个目录,其中我已经放置了网站内容
1) /var/www/website/
2) /var/www/web-site/
我的网站 - 可用&已启用网站的文件夹内容2个文件
website & web-site
website
的内容
server {
listen 443 ssl;
include snippets/self-signed.conf;
include snippets/ssl-params.conf;
location /website/ {
alias /var/www/website/;
gzip_static on;
expires max;
add_header Cache-Control public;
autoindex off;
}
server_name energy.mysite.local/website;
location / {
try_files $uri $uri/ =404;
}
}
web-site
的内容
server {
listen 443 ssl;
include snippets/self-signed.conf;
include snippets/ssl-params.conf;
location /web-site/ {
alias /var/www/web-site/;
gzip_static on;
expires max;
add_header Cache-Control public;
autoindex off;
}
server_name energy.mysite.local/web-site;
location / {
try_files $uri $uri/ =404;
}
}
这样我才能使用以下网站
https://energy.mysite.local/website/1.0.1/src/abc.js
https://energy.mysite.local/web-site/2.0.1/src/abc.js
目前https://energy.mysite.local/web-site/2.0.1/src/abc.js
工作正常。
但是https://energy.mysite.local/website/1.0.1/src/abc.js
正在给我404
页面
任何方法来完成它?
答案 0 :(得分:1)
根据您的问题,这两个位置似乎共享相同的根,在这种情况下,可能不需要单独的location
blocks和alias
directive。
例如:
server {
listen 443 ssl;
server_name energy.mysite.local;
include snippets/self-signed.conf;
include snippets/ssl-params.conf;
root /var/www;
gzip_static on;
expires max;
add_header Cache-Control public;
location / {
try_files $uri $uri/ =404;
}
}