nginx path omitted and sources cannot be found - nginx

I am currently configuring a nginx reverse proxy.
The docker instance of nextcloud is available on Port 8891
server {
listen 8888 ssl http2;
...
location /nextcloud/ {
proxy_pass http://0.0.0.0:8891/;
}
}
however when I try to navigateto the url, I have the problem, that the stylesheets etc. are not available under /nextcloud/*
instead they are getting fetched from /core/*.
How can I archive, that the sources like server.css is getting fetched from /nextcloud/, and basically the whole nextcloud web app is available under /nextcloud/?

Related

Meteor Up load balancer

My meteor application is deployed with mup.js
I would like to use balance loader for several reasons. (No downtime deployment, better user experience)
In the docs. there is a Swarm what makes a cross server load balancing, but I would have separated app containers at the same server. And they just running on different ports, what NGINX balancing
Status: Have started different app containers at the same server, but can not configure the nginx.
Having 2x mup file (1. mup.js, mup-support.js) They are pretty same, but the support runs only the app container, and connects it to the db.
mup.js:
proxy: {
domains: "domain.com",
nginxServerConfig: "./staging.nginx.conf",
loadBalancing: true,
ssl: {
// ... config
}
}
staging.nginx.conf:
upstream pass_servers {
server container1
server container2
}
server {
server_name domain.com;
listen 80 ;
access_log /var/log/nginx/access.log vhost;
include /etc/nginx/vhost.d/domain.com;
location / {
proxy_pass http://pass_servers.com;
}
}
Result: crashed nginx
Question: Is the logic fine, or should I go in a different way? If the logic is fine, what am I missing?

Redirect default (80) port to 5000 - Flask + NGINX + Ubuntu

I'm successfully able to run a flask app on my IP:5000 path. A simple Hello World program that shows the output on my browser.
Now, what I would like to do is to configure NGINX with a proxy so that if I access only IP which apparently runs on a default port 80, it should navigate to port 5000 and show output of my application.
In other words...
This is working : IP:5000 -> Output = Hello world
This isn't working: IP -> This site can’t be reached
The server settings that I want to add would be something like this.
server {
listen 80;
server_name MY_IP;
location / {
proxy_pass http://127.0.0.1:5000;
}
}
However, I'm not sure where to add this? Should it be inside http block inside /etc/nginx/nginx.conf?
Updates: Based on the answers given below, I've managed to do the following.
I did restart nginx after this. However, I'm still facing the same issue. App works on IP:5000 but does not work on IP
The configuration you have mentioned should be in a separate file, assume example.com.conf under /etc/nginx/conf.d. You can put all the configuration in /etc/nginx/nginx.conf and it'll work, it's just that for readability we create separate configuration files which would be auto included when you add it inside conf.d.
Ok, the problem is fixed. As #senaps and #Mukanahallipatna had mentioned, I created the new configuration file under conf.d.
However, the most imp step that I was missing was this part mentioned in the below link.
It is recommended that you enable the most restrictive profile that will still allow the traffic you've configured. Since we haven't configured SSL for our server yet, in this guide, we will only need to allow traffic on port 80.
Reference Link
sudo ufw allow 'Nginx HTTP'
Now, everything is working fine.
Put the working blocks in a file with any_name.conf inside the folder named /etc/nginx/conf.d and it will be loaded automatically.
You will need to restart your nginx.
update:
What are you using to serve flask? if you are using uwsgi, then you should use configurations like this:
include uwsgi_params;
uwsgi_pass unix:path_to_your.sock;
Other options for uwsgi_pass are:
uwsgi_pass localhost:9000; #normal
uwsgi_pass uwsgi://localhost:9000;
uwsgi_pass suwsgi://[2001:db8::1]:9090; #uwsgi over ssl
If you are using gunicorn to serve your flask app, then your current configs should be fine, check if your app is running and if you can get your index page or not using 5000 port, then check for other problems. your configs looks good, maybe it's a problem on flask not being run?

Nginx: Setting up SSL-passthorugh

I'm trying to configure SSL-passthrough for multiple webapps using the same nginx server (nginx version: nginx/1.13.6), but when restarting the nginx server, I get an error complaining that
nginx: [emerg] "stream" directive is duplicate
The configuration I have is the following:
2 files for the ssl passthrough that look like this:
server1.conf:
stream {
upstream workers {
server 192.168.1.10:443;
server 192.168.1.11:443;
server 192.168.1.12:443;
}
server {
listen server1.com:8443;
proxy_pass workers;
}
}
and server2.conf:
stream {
upstream workers {
server 192.168.1.20:443;
server 192.168.1.21:443;
server 192.168.1.22:443;
}
server {
listen server2.com:8443;
proxy_pass workers;
}
}
If I remove one of the two files, then nginx starts correctly.
How can this be achieved?
Thanks,
Cristi
Streams work on Layer 5, and cannot read encrypted traffic (which is Layer 6 on the OSI model), and thus cannot tell apart requests hitting server1.com and server2.com unless they are pointing to different IPs.
This can be solved by one of the following solutions
Decrypt the traffic on nginx, then proxy-pass it to backend processes/wockers using HTTP.
Bind server1.com to a port that is different to server2.com.
Get an additional IP address and bind server2.com on that.
Get an additional load balancer and move server2.com there.

How to manage many URLs / domains

I would like to get following situation:
I have domains: xxx.com zzz.com and yyy.com
I have one server: xxx.yyy.zz.qq
I would like to configure glassfish to start listening on port 80, and basing on the URL choose proper base catalog for my sites i.e.:
Scenario 1: Visitor is entering url xxx.com or www.xxx.com -> Glassfish receive request on port 80 and pick up catalog: ./glassfish4/myXXXcom/ where index.html for xxx.com is placed.
Scenario 2: Visitor is entering url zzz.com or www.zzz.com -> Glassfish receive request on port 80 and pick up catalog: ./glassfish4/anotherSite/ where index.html for zzz.com is placed.
What have I done:
Installed glassfish 4.1 on my server.
Changed A field of my domains to my server address.
Created virtual server:
glassfish4/bin/asadmin/create-virtual-server --hosts xxx.com xxx
Created http listener:
glassfish4/bin/asadmin create-http-listener --listeneraddress xxx.com --listenerport 80 --default-virtual-server xxx xxx
I think that I am doing something completely wrong here. How do I fix this problem?
If I understand correctly, what you need to do is, create two domains in glassfish or create a cluster and assign two instances of local glassfish instances. One running in port 28080 and another domain in 28081 and use nginx as the load balancer to forward the request to appropriate ports when requests comes from different domains. To make it clear, I am writing step by step
Create a new cluster in glassfish admin console
Create and assign a new local glassfish instance to cluster. This instance will be running in port 28080 and handles requests coming from example1.com
Create another glassfish domain 28081 as the port no for handling example2.com
Install nginx, this acts as proxy and forward request to appropriate
domains. Nginx will be running in port 80.
Start the cluster
Configure nginx as below. This is the crucial part
server {
listen 80;
server_name example1.com;
location / {
proxy_pass http://127.0.0.1:28080;
}
}
server {
listen 80;
server_name example2.com;
location / {
proxy_pass http://127.0.0.1:28081;
}
}
Start nginx
I hope you are familiar with creating clusters and domains in glassfish. If you are unfamiliar with creating clusters in commandline. Glassfish admin console is there, where you can achieve everything. If you need more info, please feel free to write in comments.

Using nginx to serve local files instead of remote files

Say I'm accessing www.mywebsite.com.
This website fetches the following asset:
http://www.mywebsite.com/styles/app.css
I want to access the website exactly as I normally would, with one exception:
Whenever my browser makes a request to /styles/app.css, instead of fetching it from http://www.mywebsite.com, I want to fetch it from http://localhost:3000/mywebsite/.
So instead it should be fetching:
http://localhost:3000/mywebsite/styles/app.css
Is this possible with nginx?
I tried to do it using the following server config:
{
...
server {
listen 80;
server_name mywebsite.com;
location /styles/ {
proxy_pass http://localhost:3000/mywebsite/styles/;
}
}
But even after restarting nginx (sudo nginx -s quit, sudo nginx), nothing seems to have changed.
When I browse to www.mywebsite.com/styles/app.css, I still get the same old app.css being retrieved from the server, rather than my local one.

Resources