JavaScript not executing with non-root nginx proxy_pass location - docker

I'm trying to set up nginx to reference a docker container. Ultimately, I'd like to configure nginx to direct traffic to multiple docker containers, but I'm stuggling to get the location working.
This works:
http {
server {
location / {
proxy_pass http://172.20.0.10:8000/;
}
}
}
When using the above configuration, I can go to http://<server-ip-address>/, and see the website.
However, when I try to modify the location, like so
http {
server {
location /path/ {
proxy_pass http://172.20.0.10:8000/;
}
}
}
I'm able to still able to load the page, but it doesn't appear to be executing the JavaScript. I get a white background, and can see the page HTML, but none of the info that would be populated by JavaScript shows up.
(I do have JavaScript enabled in my browser. I have tried both Chromium and Firefox, and both have the same issue.)

Related

Nginx not promoting authentication on every reload

I have tested the below nginx config:
server {
location /foo/ {
auth_basic "This part of website is restricted";
auth_basic_user_file /etc/apache2/.htpasswd;
}
}
but it is not prompting authentications popup.
Is there something else to be changed for authentication to pop up on every reload?

Ruby 6.1 with Nginx - restrict direct access to specific files

I am using Nginx server with a RoR webapplication (version 6.1.4).
I have several audio files around the site and I want to restrict direct access to them.
The page have publicly accessible part and another for registered members. Here they can upload and share mp3's through the platform.
I added the following lines to nginx configuration:
location ~* \.mp3 {
valid_referers server_names;
if ($invalid_referer) {
return 403;
}
}
This one is working fine for the hardcoded audios and prevents direct access.
But if someone logs in and traces the html for the sourcefiles of uploaded audios, it is still accessible for them. I am using ActiveStorage for managing file uploads and it is on a s3 storage.
Appreciate any ideas!
Did not check, but customize this and try:
location ~* \.mp3 { # location for .mp3 files
if (-f $request_filename) { # if file actually exists
return 301 $scheme://$server_name/RoR_APP_URI_with_auth_check/$request_uri;
}
}
This could be a good opportunity to use the Proxy design pattern. You could create a controller/action that handles user authentication and then either redirects to the appropriate url or directly serves the file using send_file. There are pro's and con's to this approach but it would be a way to authenticate requests and restrict access to paywalled content.
Here's an example from a production app I'm working on:
def avatar_proxy
if Rails.env.development?
tmp_file = open(current_user.avatar.path)
else
url = current_user.avatar.url
tmp_file = open(url)
end
send_file tmp_file, :type => current_user.avatar.content_type, disposition: 'inline'
end

Nagios/Icinga - find host by custom variable with cmd/status.cgi

I'm looking for solution how to get a hostname from Nagios/Icinga by searching it by custom variable with cmd/status.cgi.
I have a custom variable with unique specific IDs on every host. I have to get the hostname by searching on ID. There is a documentation for CGI commands but I could not find the needed functionality: https://icinga.com/docs/icinga1/latest/en/cgiparams.html
UPD: I am using python for CGI requests. Maybe there is also a library to do that.
Does anyone know, if it is possible?
For Nagios at least, this is possible. You can call the host details on the objectjson.cgi for a hostgroup and in your result.json(), you would have the custom_variables for each of the hosts. With that, you can map an ID to the hostname.
make your request to https://<your_url>/nagios/cgi-bin/objectjson.cgi?query=hostlist&details=true&hostgroup=<your_hostgroup>
{...
"data": {
"hostlist": {
"<host1>": {
....
"custom_variables": {
<custom host variables dict>
},
"<host2>": {
....
}
}
}
}
untested! using python's requests module:
hostlist = result.json().get('data').get('hostlist')
id_map = {hostlist.get(host).get('custom_variables').get('your_id_key'):host for host in hostlist.keys()}

Serve different pages with the same URL

I have two HTML pages. a.html is a mobile version of my site, b.html is the desktop version. How can I set these two pages to use the same URL?
It is very easy and I have already implemented this. You can check out wittyfeed.com, it serves different files for mobile and desktop.
It can be done as follow,
http {
....
map $http_user_agent $ind {
"~*mobile" a.html;
default b.html;
}
server {
...
index $ind;
...
location / {
try_files $uri $uri/ $ind;
}
}
}
The above code runs as, it sets value for variable $ind, as a.html if the request comes from mobile or b.html otherwise. Then, accordingly it tries to fetch the file. :)
Edited w.r.t. comment below, *not tested,
http {
...
map $http_user_agent $proxy_addr {
"~*mobile" test-qa.firebaseapp.com/mobile;
default localhost:8080/test/jsp/index.jsp;
}
server {
...
location /test {
proxy_pass $proxy_addr;
}
}
}

yo gulp-webapp + BrowserSync

I want to use gulp-webapp with php server (not the default built in one).
my gulp file looks like this, but here is the extracted part:
gulp.task('serve', ['styles'], function () {
browserSync.init("*", {
debugInfo: true,
open: true,
proxy: "localhost/nl_mobile/app"
})
});
gulp.task('watch', ['serve'], function () {
// watch for changes
gulp.watch(['app/*.html'], reload);
gulp.watch('app/styles/**/*.scss', ['styles']);
gulp.watch('app/scripts/**/*.js', ['scripts']);
gulp.watch('app/images/**/*', ['images']);
gulp.watch('bower.json', ['wiredep']);
gulp.watch('app/bower_components/**/*.scss', ['styles']);
gulp.watch('app/bower_components/**/*.js', ['scripts']);
});
The problem is, the changed content inject to the browser but it does not refresh itself, i have to refresh it manually.
I also changed this line:
// .pipe(gulp.dest('.tmp/styles'))
.pipe(gulp.dest('app/styles'))
because, i cannon't specify
server: {
baseDir: ['app', '.tmp'],
directory: true
},
because it will fire up some kind of http based server which doesn't understand php :(
In case you didn't run across the answer already, Browser Sync supports a proxy config option that can be used to reverse proxy another web server, e.g. Apache, php -S. You'll also need to watch the PHP files in your project for updates to trigger the reload in the attached browsers. Happy to expound with examples as needed.

Resources