I have an django based website that's presented through gunicorn with nginx as reverse proxy. It's on port 81.The relevant portion of the configuration file looks like this:
upstream elearning_server {
server localhost:8000;
}
server {
listen 81;
......
If you go to:
http://webaddress:81
the first time after you log in, it removes the port number and fails to connect to the website. If you then put the port number back into the url it works fine.
Has anyone got any suggestions of what I can try to fix this problem.
What is happening is that your web server, as part of the login process is 'redirecting' your browser to a different web address. The problem is that the web address your browser is being redirected to doesn't exist, because it is being redirected to the wrong web address. When you modify the web address, you are correcting this error.
Obviously the solution is to correct this problem in the code, so you are sent straight to the correct web address without you needing to correct this.
The solution depends on your code. It is worth looking at it with the following in mind.
Is there something like:
return HttpResponseRedirect('http://website/dir/')
in your code somewhere? This would need to be altered to include the port number, i.e
return HttpResponseRedirect('http://website:81/dir/')
Or, even better,
return HttpResponseRedirect('/dir/')
(This will mean that it won't matter what port the server is on, because the redirect is 'relative'. This would be the usual way to code this sort of thing.)
If a quick perusal of the source doesn't cast any light, I would suggest that the next step would be to look in the access logs (and maybe error logs) from the web server, and look for '3xx' type messages, probably '301' and '302' messages, and this may give you some clue as to what is happening, and where in the code.
Related
my original page is http://www.stahlbaron.de/
since 2 days, http://www.joma-topflex.ru/ is pointing to my page. I realized this and added ALLOWED_HOSTS = ['.stahlbaron.de'], but didnot help. the bad URL still pointing to my page.
what can I do? I used nginx, uwsgi to deploy the page. Ngix doesnot have deny www.joma-topflex.ru; option unfortunately.
There are two possibilities:
The owner of the copy actually stole your code and the database, which is unlikely. This can be easily checked — just add a change to some page on your website and see if it appears on the doppelgaenger. If the copy is independent then nothing will change there. Don't forget to use Ctrl+F5 to avoid seeing cached contents.
If this is the case, you can report abuse to the copy's hosting provider. In fact, you should do it in any case.
If that copy is just a proxied mirror to your website, blocking its IP will solve the problem. You can do it in Nginx by modifying your configuration like this:
geo $bad_client {
default 0;
78.47.49.3/32 1;
}
server {
...
if ($bad_client) {
return 403;
}
add_header X-Frame-Options SAMEORIGIN;
...
}
This is also a good idea to set the header X-Frame-Options to SAMEORIGIN (see the example above), which guarantees that nobody will make a copy of your site on another domain using an iframe.
EDIT:
And now this just gets funny. What happens here is this: some (probably long) time ago someone bought a hosting package from Hetzner, registered the domain www.joma-topflex.ru and pointed it to the IP that Hetzner had given him or her. And that IP was, as you might have guessed by now, 78.47.49.3.
After a while this person probably lost interest to the project and stopped paying to Hetzner. Hetzner, in turn, reassigned the IP to the new client — you. But the domain name www.joma-topflex.ru had never been pointed to another IP by the domain's owner, which often happens to abandoned projects.
So, there is actually no bad guy here. The owner of www.joma-topflex.ru likely doesn't even know that his domain works once again.
The real problem here is your Nginx configuration, which proxies any request to your server to your Django application. What you need to do is explicitly set your domain as the only acceptable server name like this:
server {
# Delete any other server_name you find around and add this:
server_name www.stahlbaron.de;
...
}
The funny part is, you can use domain www.joma-topflex.ru as long as it points to your server. For example, you can add another server block to your Nginx configuration, set directive server_name with "www.joma-topflex.ru" and use it for another Django application, or whatever else you like.
EDIT 2:
Incidentally, the domain joma-topflex.ru is paid till 2015.04.26 and most likely will not be prolonged. In other words, you can even do nothing and the problem will solve itself in two days.
I am trying to get a Linksys router with the latest DD-WRT (v24-sp2) in my house connected, via Comcast, to an external Squid (v3) proxy that I am running on AWS. When I connect over the WiFi to the DD-WRT router, it connects to the Squid proxy, but I get the nasty message (abbreviated here to show relevant part):
While trying to retrieve the URL: /
Note the backlash. I get this when I go to a root domain, like www.cnn.com. If I go to a page under a site, like www.cnn.com/today (fake link used for example only), that returns and error like:
While trying to retrieve the URL: /today
Again, notice the "/today", as if the root domain has been removed, and the string to the right of the domain name is being searched on.
For some background, I have installed Squid as generally as possible, and have done it on two servers with the same results. I get this same error no matter what domain I go to. Also, if I switch my network on my Mac to use this Squid proxy, it works fine. Only the connections from the DD-WRT give this error.
I have tried the instructions on the DD-WRT site with no luck. Others seem to have gotten this working well, so I assume I am making a configuration mistake.
Any clues for me? TIA...
I want to make a server written in C++ to power my game. I learned the basics of sockets and wrote a basic chat program that worked well. Now I want to create an HTTP server like Apache, but only for the AJAX request-response part.
I think just for the beginning i copied one Apache response text, and i sent the exact response with the C++ server program.
The problem that is that the browser (Firefox) connnects to the apache and everything works fine, except all of the requests get a correct response.
But if i send this with the C++ client, then FireBug tells me that the response status is OK (200) but there is no actual response text. (How is this possible?)
This response-text is exactly the same what apache sends. I made a bit-bit comparison and they were the same.
The php file wich is the original response
<?php echo "AS";echo rand(0,9); ?>
And the origional source code:
Socket.h http://pastebin.com/bW9qxtrR
Socket.cpp http://pastebin.com/S3c8RFM7
main.cpp http://pastebin.com/ckExuXsR
index.html http://pastebin.com/mcfEEqPP < this is the requester file.
ajax.js http://pastebin.com/uXJe9hVC
benchmark.js http://pastebin.com/djSYtKg9
jQuery is not needed.
The main.cpp there is lot of trash code like main3 and main4 functions, these do not affect the result.
I know that the response stuff in the C++ code is not really good because the connection closing is not the best; I will fix that later now I want to send a success response first.
the problem:
the index.html is served through apache on port 80. the browser loads it and starting sending requests.
The request file (program) was on another port , on the 8888 port, which already is a different server which dont enables ajax (dont know why) to get the post data. the program can still communicate with remote servers but cant see the response.
after one whole day i tested a lot with the fiddler program , captured the responses, and that method helped me.
I used the fiddler program to capture the the good answer and to capture the bad. They were the same. After this i turned off my socket application, and forced fiddler to auto respond, and the answer from the 'bad' answer still bat. So after that i replaced the bad with the good and nothing happedned. The bad answer with the good text still bad on the :8888 port but the other on the original :80 port was good, but they were absolutly the same and the same program sended it (fiddler) i think there is something missing if the response is not on the same server address (even not the same port).
after this i thought maybe there is a missing header file, or something ike this.
So i configurated apache to listen on the 80 port, loaded in the index.html. after this i shut down the apache server and changed the port to 8888 and i run the ajax requests and i recognized that they are wrong, but they were sent by the apache, and all of the previorus requests (on the same port) were good. so the problem is only with the ajax stuff :D
many thanks to Tony Lee for the Fiddler suggestion.
Actually there is no solution but there is an answer why the problem exists.
I don't know how you're verifying bit-by-bit - if you used fiddler to capture the traffic then this is a mystery.
I'm going to guess the unsent buffered data is lost when you close the socket. See the MSDN article Graceful Shutdown, Linger Options, and Socket Closure. Call shutdown() before you call closesocket() to ensure a clean shutdown.
Not really an answer to your question, but you might find it useful.
Instead of Apache code you can try libevent. It has functions just to make http servers and it probably will be much faster than Apache code.
Check this link. There is some info about building http server with libevent.
I'm making an HTTP server in c++, I notice that the way apache works is if you request a directory without adding a forward slash at the end, firefox still somehow knows that it's a directory you are requesting (which seems impossible for firefox to do, which is why I'm assuming apache is doing a redirect).
Is that assumption right? Does apache check to see that you are requesting a directory and then does an http redirect to a request with the forward slash? If that is how apache works, how do I implement that in c++? Thanks to anyone who replies.
Determine if the resource represents a directory, if so reply with a:
HTTP/1.X 301 Moved Permanently
Location: URI-including-trailing-slash
Using 301 allows user agents to cache the redirect.
If you wanted to do this, you would:
call stat on the pathname
determine that it is a directory
send the necesssary HTTP response for a redirect
I'm not at all sure that you need to do this. Install the Firefox 'web developer' add-on to see exactly what goes back and forth.
Seriously, this should not be a problem. Suggestions for how to proceed:
Get the source code for Apache and look at what it does
Build a debug build of Apache and step through the code in a debugger in such a case; examine which pieces of code get run.
Install Wireshark (network analysis tool), Live HTTP Headers (Firefox extension) etc, and look at what's happening on the network
Read the relevant RFCs for HTTP - which presumably you should be keeping under your pillow anyway if you're writing a server.
Once you've done those things, it should be obvious how to do it. If you can't do those things, you should not be trying to develop a web server in C++.
The assumption is correct and make sure your response includes a Location header to the URL that allows directory listing and a legal 301/302 first line. It is not a C++ question, it is more of a HTTP protocol question, since you are trying to write a HTTP server, as one of the other posts suggests, read the RFC.
You should install Fiddler and observe the HTTP headers sent by other web servers.
Your question is impossible to answer precisely without more details, but you want to send an HTTP 3xx status code with a Location header.
I'm trying to implement Facebook Connect on a website with .NET MVC using C#.
I've followed the instructions here: http://wiki.developers.facebook.com/index.php/Trying_Out_Facebook_Connect step by step. I can make the login work as in that when I log in through the site I'm also logged into Facebook.
In order to work with this in the server I think I need to access the cookies Facebook is supposed to leave like:
APIKEY_user
APIKEY_session_key
...
as mentioned here http://wiki.developers.facebook.com/index.php/Verifying_The_Signature.
The thing is I'm not getting any of these cookies. I've googled and it seems like I'm the only person with this problem. Any ideas as to what I could be doing wrong ? Has this happened to anyone else ?
The issue was that I was developing locally using localhost.
I resolved the problem by changing the settings for the application to point to a certain web address instead of localhost and changing my hosts file lo point that same web address to 127.0.0.1
from the UI/client-side perspective, always insure you have the correct path indicated for the xd_receiver file in your FB.init() method.
Firecookie is very useful for seeing what Cookies are/aren't being set.