I would like to host a blog at a subfolder of my domain, which is covered by a django app. I'm most of the way there, but I need some help getting over the finish line, as it were.
Currently, if I go to domain.com, the django app is served correctly. If I go to domain.com/blog/, the blog is served correctly. However, if I go to domain.com/blog (note the missing trailing slash), the urlconf returns a URL not found error.
I've tried a couple of things, including:
Reordering the Alias, Directory, and WSGIScriptAlias statements in my Apache configuration
Having the django urlconf trap the domain.com/blog condition and redirect to domain.com/blog/ (probably unsurprisingly causing an infinite loop of redirects)
What are my next steps?
Here is the relevant part of my Apache conf:
Alias /blog/ /var/www/blog/
<Directory /var/www/blog/>
AllowOverride All
Order deny,allow
Allow from all
</Directory>
I haven't used Apache in years, but try aliasing just /blog instead of /blog/. The problem currently is that Apache is not catching it, so it's being passed to Django. If that doesn't work, you might also try setting up a 301 redirect in your Apache conf to redirect to the slash version, thereby avoiding Django altogether.
Related
A couple weeks ago, I had a wonderful time setting up an Apache and Django configuration to work while forcing SSL and operating behind an AWS load balancer.
Now that it is all working nicely, I'm still constantly receiving the common "Invalid HTTP_HOST header" error, and trying to figure out the right way to go about fixing it.
Searching has brought me to the following answer regarding the Apache configuration:
How to disable Django's invalid HTTP_HOST error?
Which recommends placing the following settings inside the <Directory></Directory> block in the VirtualHost file:
SetEnvIfNoCase Host .+ VALID_HOST
Order Deny,Allow
Deny from All
Allow from env=VALID_HOST}
This works, but according to Apache (https://httpd.apache.org/docs/2.4/howto/access.html) this method is deprecated.
I've read through the Apache docs but when I tried using the following code it just shut down access to the site and gave me a "Not Authorized" error.
<RequireAll>
Require host example.org
</RequireAll>
Not entirely sure what I'm missing. I know I can solve the problem using the first answer, just trying to figure out the "right" way using code that isn't deprecated. Site is using WSGIDaemonProcess to run the Django App and has the following set to force the SSL through AWS
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTP:X-Forwarded-For} !=""
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI}
No need to use mod_setenvif as HTTP_HOST is already a variable and you can evaluate it directly.
<Directory /var/www/html/>
Require expr %{HTTP_HOST} == "example.com"
Options
</Directory>
So, after messing with this for a long time I figured out that the problem I was dealing with may have something to do with the hostname reverse DNS lookup failing, since the IP address was pointing to an AWS EC2 instance instead of my domain.
After finally giving up on getting it right I returned to the post on how to disable the log error, and tried using the env variable, which seems to be working.
Apparently the correct format for Require is:
<Directory /var/www/html/>
SetEnvIfNoCase Host example\.com VALID_HOST
Require env VALID_HOST
Options
</Directory>
These guys had it right, just need to update it for the current "Require" directive.
How to disable Django's invalid HTTP_HOST error?
I have a complex setup wherein am having Django 3 sub-projects kind of thing hosted on single Apache via mod wsgi.
I want to have www prepended on all addresses for one of these as some payment gateways are behaving improper without www URLs. Now, .htaccess's canonical redirect messes up the other 2. Using PREPEND_WWW from common middleware works only for foo.jp and not for foo.jp/bar/* and so on...
Similarly, I also tried to create an index.php, pointed to it from sites-enabled in apache and used header redirection to www.foo.jp for foo.jp...
Please tell me a way for all URLs i.e. anything foo.jp/, foo.jp/bar/ etc. to www.foo.jp/, www.foo.jp/bar/ and so on...
Regards !
I figured this out...
In the apache/sites-enabled/000-default
Basically, the default apache virtual host file which is read before other domain's virtual host files I added this:
<VirtualHost *:80>
ServerName playism.jp
Redirect permanent / http://www.foo.jp/
</VirtualHost>
Now, it is redirecting for everything... without the .htaccess which was messing it up !
Recently I used WAMP server to set up a server environment in a Windows machine. Everything works great, but I have a little problem: everyone can access the wampserver homepage, therefore they can see other webpages hosted in the same server, the server file system, etc.
The URLs of the webpage have the following format: hostname/project1, hostname/project2... The main problem is that, anyone can see all the projects that are hosted by going to the direction of the hostname because this will lead to the wampserver homepage, and I would prefer that this homepage could be accessed only in the localhost of the windows host. Is there any way to do that? I'm guessing that I will need to modify some parameters in configuration files, but I have no idea wich ones...
If you intend to block access to all sites hosted on this computer from outside access, you can do this in your main apache configuration file at <installation drive>/wamp/bin/apache/Apache<version number>/conf/httpd.conf. .htaccess is more for per-site configurations, though it will certainly work if you put it in the main www directory.
To disallow outside access to the www folder (open by default) find the part of the apache configuration file (path shown above) that looks like:
<Directory "<installation drive>/wamp/www">
# There will be comments here and some options like FollowSymLinks and AllowOverride
Order Allow,Deny
Allow from all
</Directory>
And change it to:
<Directory "<installation drive>/wamp/www">
# There will be comments here and some options like FollowSymLinks and AllowOverride
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Directory>
If your goal is not to block outside access to all of your sites, it would help to know more about your set up. And if your goal is only to block the 'localhost' page and still allow access to, say, 'localhost/site1' then this question may be a duplicate of this.
Edit:
As you point out, there is not a good resolution for the question I linked. Assuming you have your public sites set up as virtual hosts in a sub folder of the webroot like:
|-wamp_root
|-www
|-vhosts
|-public_site_1
|-public_site_2
Then you can go back into your httpd.conf and add this below your /wamp/www/ rule:
<Directory "<installation drive>/wamp/www/vhosts/">
# There will be comments here and some options like FollowSymLinks and AllowOverride
Order Allow,Deny
Allow from all
</Directory>
This will allow anything in the www folder to be accessed only locally, and anything in the vhosts sub folder to be accessible outside. Again, remember to restart Apache whenever you change this file.
It should be possible to block other users using the windows firewall.
You could also use a .htaccess file like this one:
Order deny,allow
Deny from all
Allow from 127.0.0.1
You will have to make sure that AllowOverride is set to All in the apache configuration and that the .htaccess wil be applied to all subdirectories too, otherwise your projects will still be available.
It appears (after a bit of head-scratching myself), the answer to this question was simple.
In the Windows Taskbar, left click the WAMP icon, then click 'Put Offline'.
It doesn't appear to take the entire webserver "offline", just the root homepage? and anything you've configured in your httpd.conf file to be accessible externally still stands, they are still reachable.
NOTE: The default VHOST's are still reachable though, PHPINFO and PHPMYADMIN for example!
It is not difficult.
edit the index file by notepad++
find the line &projectContents
change from &projectContents to &project---Contents
then the project title disappears.
I'm trying to set up a proxy to my corporate environment's ActiveMQ admin pages on our standard http proxy server. I have a rule in place that allows me access to the admin landing page:
ProxyPass /foobar hostname:8161/admin
ProxyPassReverse /foobar hostname:8161/admin
However, going to the "queues" page bring me to a different page appended with a unique session ID (admin/queues.jsp;jsessionid=oq37zgvxz4zkwliwdwddyon3), and I would like for this page to be accessible through the same URL as well.
Attempting to add a wildcard (*) at the end of these proxypass rules breaks the redirect. Is there a redirect rule that I need to use in conjunction with this, and how do I get any string to this host to pass through this proxy rule?
There is ProxyPassMatch that is regex based, but ProxyPass does prefix matching (i.e. a ProxyPass for /foo should catch /foo/bar too) so your current rule should work anyway.
It may be that the redirection URL doesn't match the reverse rule for some reason. I have to admit I've never managed to get a ProxyPass to Tomcat to work correctly when the front and back end context paths differ, so my advice would be to deploy the back end app at hostname:8161/foobar instead of /admin if that's an option.
I'm using FastCGI to serve my Django app, so basically it works like this: http://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/#running-django-on-a-shared-hosting-provider-with-apache
What is the best way I can serve static media (images, css, etc) from this? Thanks!
If using Apache to front the site we normally go with WSGI for connecting to django and then let Apache handle '/media/...anything...' as statically served content. It's a couple lines of config and Bob's your Uncle!
Update: I should add that most of our Django sites are on dedicated servers, but you also can do this easily at webfaction.com.
E.g.
<Location "/media">
SetHandler None
</Location>
Add any appropriate Alias directives to your web server configuration, from deepest to shallowest.
I use this in my apache conf:
Alias /static/ /path/to/static/files/
<Directory /path/to/static/files/>
Order deny,allow
Allow from all
</Directory>
If you don't have write access to your apache conf, you can do this in your .htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/path/to/media/files/
RewriteRule ^(.*)$ mysite.fcgi/$1 [QSA,L]
Or something similar. This ensures that any urls beginning with the path to your media files do not redirect to fast cgi. If you already have some conditions you can add multiple RewriteConds using [OR].