我使用NGINX web服务器来代理/绕过基于特定URI的请求到一些JAVA应用程序(atlassian产品),并为根调用创建了一个默认的登陆页面到我的域,一切都很好。但是现在我试着在我的网站配置中通过特定的位置定义提供另一个静态页面,我没有线索来修复css/js/image交付作为这个页面内的相对路径定义。
这是我的服务器路径结构:# 01 default landing page
/var/www/df-default/
d css
d js
d img
d fonts
d _external
f index.html
# 02: external source
/var/www/df-default/_external
d css
d js
d img
f impressum.html
f datenschutz.html
这是我当前的nginx站点配置:
server {
listen 80;
listen [::]:80;
listen 443 default ssl;
server_name dunkelfrosch.com
#
# ... some ssl stuff here ...
#
root /var/www/df-default;
# default landing page
location / {
try_files $uri $uri/ /index.html;
}
# proxy config for bitbucket application server
location /go/to/bitbucket {
# set 20min proxy timeout
proxy_read_timeout 1600s;
proxy_send_timeout 1600s;
proxy_connect_timeout 1600s;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_redirect off;
proxy_pass http://localhost:7990/go/to/bitbucket;
}
# external content 01: static imprint page
# + should available by calling dunkelfrosch.com/show/me/phpugdd/imprint
# - no css,js or image files will delivered using this config
# - I've to insert complete url to css/img/js inside my templates
# and have to config the location block as shown below to deliver the page
location /show/me/phpugdd/imprint {
try_files $uri $uri/ /_external/web/impressum.html;
}
# external content 02: static privacy page
# + should available by calling dunkelfrosch.com/show/me/phpugdd/privacy
# - no css,js or image files will delivered using this config
# - I've to insert complete url to css/img/js inside my templates
# and have to config the location block as shown below to deliver the page
location /show/me/phpugdd/privacy {
try_files $uri $uri/ /_external/web/datenschutz.html;
}
}
我认为我只是提出了一个位置定义块,并重新定义项目/页面根路径,以便任何$uri将通过-但不幸的是,它不会。我对这些静态页面所做的每个css/js/img uri调用都将强制传递第一个登陆页面,而不是相关文件。所以我要添加我的外部链接引用的这些文件在完整的url形式显示我的静态页面"好"。有人能帮我修吗?
更新
我尝试使用以下配置,同样的问题-没有css, js或图像文件将提供…
location /show/me/phpugdd/privacy {
root /var/www/df-default/_external/web;
index datenschutz.html;
try_files $uri $uri/ /datenschutz.html;
}
location /show/me/phpugdd/imprint {
root /var/www/df-default/_external/web;
index impressum.html;
try_files $uri $uri/ /impressum.html;
}
你离解决方案很近了。NGINX的好处之一是它非常擅长传递静态内容。然而,这将要求您知道所有静态文件的URI的开头,例如/static/js/private/myscript.js/
以/static/
开头。如果你知道这一点,那么你可以做如下的事情:
location ^~ /static/ {
alias /var/www/df-default/static/;
}
当然,这只是猜测,因为我不知道您在提供静态文件时使用的uri。如果它们以/css/
或/js/
之类的开始,它应该被try_files
指令中的第一个位置块捕获。然而,由于这种情况没有发生,我认为情况并非如此。如果此解决方案不起作用,请注释并显示静态资源的uri。