Getting multiple Django application site to resolve by port numbers - django

I have a Django website where I run multiple sites. Each application has a seperate apache instance and port assigned to it. the host.py file looks like the following
host_patterns = patterns('',
host(r'.*domain1.*', 'domain1.urls', name='domain1'),
host(r'.*domain2.*', 'domain2.urls', name='domain2'),
host(r'.*domain3.*', 'domain3.urls', name='domain3'),
host(r'.*domain4.*', 'domain4.urls', name='domain4'),
host(r'.*domain5.*', 'domain5.urls', name='domain5'),
)
for example www.domain1.com runs under an apache instance and port 8010.
Id like to create some internal monitors so I can check each site on a specific server. The only way to do this is with using port numbers of the apache instance so as http://10.10.10.10:8010 but when i try to modify my site to do this I get application errors.
either by adding a line for domain
host(r'.*8010.*', 'domain1.urls', name='domain1'),
or modifying existing line
host(r'.*domain1.*|.*8010.*', 'domain1.urls', name='domain1'),
not sure what I am doing wrong

I got this to work with the second option, i must have had a typo or something initially.

Related

Flask routing to AWS Kubernetes internal domain for some paths

I have a Flask application running on an AWS Kubernetes instance and I have some rounting problems with some specific directories.
For example when I try to access external.domain.com/test/ all works fine while at the same time accessing external.domain.com/test tries to route me to to the internal.domain.local/test/ url which is obviously not accessible from the outside.
It seems that whenever Flask builds the builds the url, e.g. using url_for, this issue comes up.
I already tried to overwrite the SERVER_NAME property which seems to be used when building urls but then the server does not start stating:
Current server name 'internal.domain.local' doesn't match configured server name 'external.domain.com'.
I am not sure whether I should try to rewrite it in the Ingress configuration using nginx.ingress.kubernetes.io/proxy-redirect-from and nginx.ingress.kubernetes.io/proxy-redirect-to but unfortunately the documentation seems to be pretty sparse.
If anyone knows how to fix this issue, thank you in advance.

Local development with Django

I am using dnsmasq on my mac in order to force the domain I'm developing for (example.com) to resolve to localhost.
This means that if I go to http://example.com:8000, it uses the local development server, which is what I want.
But it also means that if I try and go to the real example.com, that doesn't resolve to the real site, obviously - it's using localhost.
Is there a way for me to develop locally with port 8000 but also be able to view the real site (without a port - or port 80)?
EDIT:
Everyone seems a bit confused about what I'm trying to do here so let me explain.
I'm trying to develop a site so that it can display different content on any subdomain of example.com. In order to do that, I need to use the Sites framework without setting SITE_ID and let the Sites framework figure out the Site by looking at the domain in the request.
That means that I can't use localhost:8000 when testing as there is no Site with localhost as the domain. I need to use example.com:8000 (or site1.example.com:8000, site2.example.com:8000, sitewhatever.example.com) instead.
But in order to do that, I need to point example.com at localhost in the hosts file. However, that means that the real example.com doesn't resolve any more.
That's what I'm trying to figure out here.

Cubesviewer configuration for proper authentication

I'm trying to configure cubesviewer and try out the setup.
I've got the app installed running, along with cubes slicer app too.
However, when I visit the home page
http://127.0.0.1:8000/cubesviewer/
it fails popping up an error "Error occurred while accessing the data server"
Debugging with the browser console, shows a http status 403 error with the url http://localhost:8000/cubesviewer/view/list/
After some googling and reading, I figured I'll need to add rest frame auth settings. (as mentioned here.).
Now after running migrate and runserver, I get 401 error on that url.
Clearly I'm missing something with settings.py , Can somebody help me out.
I'm using the cubesviewer tag v0.10 from the github repo.
And find my settings here. http://dpaste.com/2G5VB5K
P.S: I've verified Cubes slicer works separately on its' own.
I have reproduced this. This is error may occur when you use different URL to access a website and to access related resources. For security reasons, browsers allow to access resources from exactly the same host as the page you are viewing.
Seems you are accessing the app via http://127.0.0.1:8000, but you have configured CubesViewer to tell clients to access the data backend via http://localhost:8000. While it's the same IP address, they are different strings.
Try accessing the app as http://localhost:8000.
If you deploy to a different server, you need to adjust settings. Here are the relevant configuration options, now with more comments:
# Base Cubes Server URL.
# Your Cubes Server needs to be running and listening on this URL, and it needs
# to be accessible to clients of the application.
CUBESVIEWER_CUBES_URL="http://localhost:5000"
# CubesViewer Store backend URL. It should point to this application.
# Note that this must match the URL that you use to access the application,
# otherwise you may hit security issues. If you access your server
# via http://localhost:8000, use the same here. Note that 127.0.0.1 and
# 'localhost' are different strings for this purpose. (If you wish to accept
# requests from different URLs, you may need to add CORS support).
CUBESVIEWER_BACKEND_URL="http://localhost:8000/cubesviewer"
Alternatively, you could change CUBESVIEWER_BACKEND_URL to "http://127.0.0.1:8000/cubesviewer" but I recommend you to use hostnames and not IP addresses for this.
Finally, I haven't yet tested with CORS support, but check this pull request if you wish to try that approach.

Why am I getting "Internal Server Error" running two Odoo instances (same domain but different ports)?

I have two instances of Odoo in a server in the cloud. If I make the following steps I get "Internal Server Error":
I make login in the first instance (http://111.222.33.44:3333)
I close the session
I load the address of the second instance in the same browser (http://111.222.33.44:4444)
If I want to work in the second instance (in another port), I need to remove the browser cookies first to acces to the other Odoo instance. If do this everything works fine.
If I load them in differents browsers (Firefox and Chromium) at the same time, they work well as well.
It's not a NginX issue because I tried with and without it.
Is there a way to solve this permanently? Is this the expected behaviour?
If you have access to the sourcecode you can change this file like shown below and check if the issue is solved or not.
addons/web/controllers/main.py
if db != request.session.db:
request.session.logout()
request.session.db = db
abort_and_redirect(request.httprequest.url)
And delete --> request.session.db = db
which is below this IF statement.
Try following changes in:
openerp/addons/base/ir/ir_http.py
In method _handle_exception somewhere around line 140 you will find this piece of code:
attach = self._serve_attachment()
if attach:
return attach
Replace it with:
if isinstance(exception, werkzeug.exceptions.HTTPException) and exception.code == 404:
attach = self._serve_attachment()
if attach:
return attach
You can perfectly well serve all the databases with a single OpenERP server on your machine. Unfortunately you did not mention what error you were seeing and what you expected as a result - makes it a bit harder to help you ;-)
Anyway, here are some random ideas based on the information you provided:
If you have a problem with OpenERP not listening on all interfaces, try to specify 0.0.0.0 as the xmlrpc_interface in the configuration file, this should have OpenERP listen on 8069 on all IPs.
Note that Apache is not relevant if you're connecting to e.g. http://www.sample.com:8069/?db=openerp because you're directly connecting to OpenERP. If you want to go through Apache, you need to setup ReverseProxy rules in your vhost configs, and OpenERP does not need to listen to all public IPs then.
OpenERP 6.1 and later can autodetect the database name based on the virtual host name, and filter the name of the available databases: you need to start it with the --db-filter parameter, which represents a pattern used to filter the list of available databases. %h represents the domain name and %d is the first domain component of that domain. So for example with --db-filter=^%d$ I will only see the test database if I end up on the server using http://test.example.com:8069. If there's only one database match, the list is not displayed and the user will directly end up on the right database. This works even behind Apache reverse proxies if you make sure that OpenERP see the external hostname, i.e. by setting a X-Forwarded-Host header in your Apache proxy config and enabling the --proxy mode of OpenERP.
The port reuse problem comes because you are trying to start multiple OpenERP servers on the same interface/port combination. This is simply not possible unless you are careful to start just one server per IP with the IP set in the xmlrpc_interface parameter, and I don't think you need that. The named-based virtual hosts that Apache supports are all handled by a single master process that listens on port 80 on all the interfaces. If you want to do the same with OpenERP you only need to start one OpenERP server for all your domains, and make it listen on 0.0.0.0, port 8069, as I explained above.
On top of that it's not clear what you would have set differently in the various config files. Running 40 different OpenERP servers on the same machine with identical code sounds like a lot of overkill. OpenERP is designed to be multi-tenant so that many (read: hundreds) of databases can be served from the same server.
Finally I think this is the expected behaviour. The cookies of all websites are stored specifically for each website (for each domain) in the web browser. So if I only change the port the cookies of the first instance are in conflict with the cookies of the other instance because the have the same domain (111.222.33.44 in my example).
So there are some workarounds:
Change Domain Locally
Creating a couple of domain name in my laptop in /etc/hosts:
111.222.33.44 cloud01
111.222.33.44 cloud02
Then the cookies don't interfere with each other anymore. To access to each instance
http://cloud01:3333
http://cloud02:4444
Broswer Extension. Multilogin or Multiaccount
There is another workaround. If I use this chromium extension the problem disappears because the sessions are treated separately:
SessionBox

How do I stop re-directs to another website?

I created my own local website(to run in my localhost) called http://testrb.com. But when I key that in a browser, it is redirecting to someone else's https://www.testrb.com. I want to prevent this and view my testrb.com. How do I do this? I am using apache webserver
I think the problem cames from the browser: since third level domain "www." browsers now a days are trying to add that domain to the URL. To solve that try to type all the address adding also http://.
If still not working you should try to use a local DNS: add the alias in your /etc/resolv.conf to the line starting with 127.0.0.1 appending the domain name testrb.com separated with a space(in UNIX systems).