Local development with Django - 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.

Related

What is the correct way to do a redirection from www. to the naked domain (Server or App or Domain Provider)?

I currently have an app that works with both www.domain.com and domain.com. Considering that this seems to be bad for SEO, I want it to always redirect to the naked domain.
My app works in this way:
Server: Google Cloud Platform (App engine)
App: Django
Domain provider: Godaddy
As I have researched the redirection can be done from any of these 3 options. So I want to ask: What is the best option and why?
I tested to do the redirection with GoDaddy on App Engine (An A record for www pointing to #) but when I set my custom domain in App Engine, I noticed that for the www.domain a C Record pointed to ghs.googlehosted.com setting was required in the app engine panel, I omitted that in order to do the redirection in GoDaddy, but the app wouldn't load when visiting from www.domain, a 404 error appeared (Also tried by omitting the addition of the www.domain altogether in app engine settings) So I wasn't able to accomplish this in the same fashion than an app that is hosted in a single server.
I think the easiest way would be to handle this inside the app itself like this site mentions

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).

ColdFusion built in web server, how to test from a domain

So I want to do this:
myapp.com -> localhost (ColdFusion local web server)
I can currently only do this:
localhost/myapp_folder/
Any ideas on how to achieve this using built in web server?
One solution is to add
127.0.0.1 myapp.com
to your windows/etc/hosts file
(You'll need to do this as an administrator, so right click notepad and 'Use as administrator', browse to the file and edit that way).
This will make all requests on your local machine for myapp.com point to 127.0.0.1 (i.e localhost) - don't forget to remove it when you're done testing, as it will obviously stop you looking at the real site when you go live with it.
This will allow you to do myapp.com/myapp_folder/, but if you want to map /myapp_folder/ to the root of the myapp.com domain using the technique above, you'll have to use something more sophisticated like apache or IIS.

Coherence - Cookie Session Sharing between Applications Hosted on Different Servers

Coherence - Cookie Session Sharing between Applications Hosted on Different Servers
i have some web application on different servers i need them to have shared cookie
session in browser.
i want to assign same domain to all of them with different urls.
how can i implement this?
is it actually gonna work?
i want to do it with virual host on a proxy server.
The first way that comes to mind is to create a symbolic link in your DocumentRoot to a mounted directory which exists on another server. If you do this cross-server and for each application, then no matter which server people arrive at (due to load balancing, etc.) each server has a 'complete' set as far as apache is concerned but actually you still have the different data in its respective place.
In your /html/ directory (example DocumentRoot) you would have:
application1/
application2 -> /mnt/application2/
application3 -> /mnt/application3/
Then you'd set up the mount - for example - so a df would have:
192.168.1.2:/var/www/html/application2 ... /mnt/application2
192.168.1.3:/var/www/html/application3 ... /mnt/application3
Doing it this way keeps the guy on the same site as far as apache and his browser, etc. are concerned and you are definitely using the same domain, but essentially just splitting the file system between servers based on url.