I am using django, nginx and apache. When I access my site with a URL (e.g., http://www.foo.com/) what appears in my browser address is the IP address with admin appended (e.g., http://123.45.67.890/admin/). When I access the site by IP, it is redirected as expected by django's urls.py (e.g., http://123.45.67.890/ -> http://123.45.67.890/accounts/login/?next=/)
I would like to have the name URL act the same way as the IP. Where should I be looking to make this happen?
Do you have virtual domains?
If so, your domain name and your ip address may be served differently.
Related
I have a website in Django, hosted in Heroku.
I have 2 domains, registered in different places:
mysite.com and mysite.com.br
I don't want to be penalized by Google for having 2 domains with the same website, therefor I would like to redirect everyone who enters mysite.com.br to mysite.com.
I entered in the DNS mysite.com.br(Not hosted anywhere) CNAME mysite.com(hosted in Heroku), which makes the user actually access the Heroku content, but the url keeps the .BR ....
So the Heroku support told me to do the redirection in the application. In this case, what's the best practice to redirect? I would imagine to do that in the url.py, but how can I do that if the "path" doesnt read the domain?
Thanks.
You can't do this in the URLs. I would write some middleware to check the host via request.get_host and redirect if you're not on the canonical one.
In fact it looks like someone has already written this: django-enforce-host.
Within my settings.py file, when I use ALLOWED_HOSTS of either my domain name or '*', I'm able to access my website. When I indicate only my server's static IP address, I get a 400 Bad Request error. Based on what I've read, this should work. Any thoughts as to why it might not be working?
I should mention that my site will be hosting a chaning list of domains, so it's important that I be able to use IP address in allowed hosts as opposed to a list of domain names.
Thanks
The WSO2 AM site has been assigned a domain, puaki-uat.mpi.govt.nz. however, the site will automatically redirect to ip address after typing the domain name, which will results in mismatch signed certificate,
Expected always use domain name to match a security certificate,
Could please anyone can tell me how to prevent the site from switching to IP address?
Thanks, Sean
It looks like you haven't configured the hostname in carbon.xml. Go to wso2am-1.10.0/repository/conf/carbon.xml and change the following tags.
<HostName>puaki-uat.mpi.govt.nz</HostName>
<MgtHostName>puaki-uat.mpi.govt.nz</MgtHostName>
Is it possible to handle sub-domains in Django without having each of them registered with registrar, provided i have purchased and setup the domain?
Suppose i own example.com. I have purchased it, and setup it to point to my website at some hosting service. But, did not add a sub-domain blog.example.com. Then, can i serve some webpage at blog.example.com?
How request.subdomain in django-subdomains (doc) library is supposed to be used?
After all, I found an answer.
Instead of registering each subdomain separately with the registrar, We should register a wildcard DNS entry for the domain so that all expected subdomain will point to that one. Then configure the web server to catch all subdomains. An example I got for nginx is:
server {
server_name example.com www.example.com;
root www/pub;
}
server {
server_name ~^(.*)\.example\.com$ ;
root www/pub/$1;
}
Then using django-subdomains library (doc) we can get the sub domain from the views or middlewares. Based on that we can redirect the view to wherever wanted using django. This is the vague idea. Anyone experienced please elaborate. An example, http://sarahah.com gives a sub domain for every user. This is where I found this is possible. But don't know how they implement it.
A discussion is found in this reddit page.
I have the following set up.
On my dns:
an A name record that points my domain to an IP addres
On my server:
nginx -> gunicorn -> django
But when I submit a form (e.g. log in form) the address in the URL bar changes from my domain name to my IP address. This causes a Cross Domain Error.
This happens on forms and when I access mydomain/admin
when I access pages my domain name in the URL bar remains intact. When I go to mydomain/admin it automatically switches to the IP w/o submitting any other forms. Any other time I have to submit a form for it to change to the IP address.
All my media and everything use mydomain in the path. It is the strangest thing. I only first noticed it when I went to my admin page, but didnt think much of it. But I just added a few forms and now I can't submit the forms because the forms try to submit to the IP address causing the cross domain error.
I should add teh forms are auto generated by django-registration.
Look for your IP in your settings.py file. It could be a setting like MEDIA_URL set to use your IP and not your domain.
This has to mean that your forms are configured to submit to the IP address. Look at the source of your form and look for the form tag:
<form action="http://(ip here?)/form/" method="GET">
Make sure that IP address isn't inserted there. You could use a relative URL. I normally leave it blank since most of my forms are processed by the same view that generated the form to begin with.
I'm assuming that you were developing locally at some point and this did not occur so I'd suggest it's something in your Nginx config. Can you use Firebug/Web Inspector to see if there's any redirects happening from your domain to your IP?
I'd also check to make sure that your Site's URL is correctly set up in the admin. Sometimes this can cause incorrect urls although I don't think the cases you've mentioned apply.