Reputation: 15
I'm using a NGINX webserver to proxy/bypass requests based on specific URI's to some JAVA applications (atlassian products) and created a default landing page for root calls to my domain and everything went fine. But now I try to deliver another static page by specific location definition inside my sites config and I don't have a clue to fix the css/js/image delivery as relative path definition within this pages.
Here is my server path structure:
# 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
Here is my current nginx site config:
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;
}
}
I thought that I've just present a location definition block and redefine the project/page root path so that any $uri will be passed through - but unfortunately it will not. Every css/js/img uri call I made for those static pages will forcefully deliver the first landing page not the related file(s). So I've to add my external link references for those files in complete url form to show up my static pages "fine". Can anyone help me fixing that?
update
I've try to use the following config, same issue - no css, js or image files will be provided ...
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;
}
Upvotes: 0
Views: 987
Reputation: 1464
You're really close to the solution. One of the benefits of NGINX is that it's really good at delivering static content. However, this is going to require you know the start of the URI of all your static files, eg /static/js/private/myscript.js/
begins with /static/
. If you know this, then you can do something as follows:
location ^~ /static/ {
alias /var/www/df-default/static/;
}
Of course, this is just speculation because I don't know the URIs you're using when serving the static files. If they begin with /css/
or /js/
and the like, it should've been caught by your first location block in the try_files
directive. However, since this is not happening, I assume it's not the case. If this solution doesn't work, please comment and show what the URIs for the static resources are.
Upvotes: 1