I am trying to map a URL based on the filename it has to a fileshare directory.
Here is the URL that i am using
http://x.x.x.x/606547/abc.xyz.aaa/MOVIE/some.video.file-xxxxxxxx.nff?c=564378
(Where .nff is file extension).
And here is the ALiasMatch settings i have configured in default sites config file.
The apache2 is running on ubuntu.
AliasMatch ^/[.?]/(*.nff)$ /srv/samba/Assets/$1
<Directory "/srv/samba/Assets">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
#Order deny,allow
#Deny from all
#Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
I am getting forbidden error when i runt hat URL in browser. I file directory/file permissions are correct.
Can you anyone please suggest is this problem with regex or problem with configuration ?
Your expression is incorrect, using a preceding * before the dot . will not be recognized.
Try using the following:
AliasMatch /([^/]*\.nff).*$ /srv/samba/Assets/$1
Can you try this regex instead:
AliasMatch /([^./]+\.nff)$ /srv/samba/Assets/$1
Related
I'm trying to match a URL with multiple params and use reverse proxy to load some other content, for some reason the Location Tag isn't working.
Following is my httpd.conf file
<Location "/tracker/">
ProxyPass "http://website.com:8290/track.js"
ProxyPassReverse "http://website.com:8290/track.js"
Order allow,deny
Allow from all
</Location>
<Location "/tracker/csc-event?p=([^\s]+)&s=([^\s]+)&v=([^\s]+)&e=([^\s]+)&c=([^\s]+)&n=([^\s]+)&f=([^\s]+)&l=([^\s]+)&i=([^\s]+)&j=([^\s]+)&k=([^\s]+)&w=([^\s]+)&h=([^\s]+)&t=([^\s]+)&x=([^\s]+)">
ProxyPass "http://website.com:8290/csc-event?p=([^\s]+)&s=([^\s]+)&v=([^\s]+)&e=([^\s]+)&c=([^\s]+)&n=([^\s]+)&f=([^\s]+)&l=([^\s]+)&i=([^\s]+)&j=([^\s]+)&k=([^\s]+)&w=([^\s]+)&h=([^\s]+)&t=([^\s]+)&x=([^\s]+)"
ProxyPassReverse "http://website.com:8290/csc-event?p=([^\s]+)&s=([^\s]+)&v=([^\s]+)&e=([^\s]+)&c=([^\s]+)&n=([^\s]+)&f=([^\s]+)&l=([^\s]+)&i=([^\s]+)&j=([^\s]+)&k=([^\s]+)&w=([^\s]+)&h=([^\s]+)&t=([^\s]+)&x=([^\s]+)"
Order allow,deny
Allow from all
</Location>
When I hit: https://website.com/tracker it works fine
But not with the other location, for eg If I hit:
https://website.com/tracker/csc-event?p=0%3Ajodv6q8w%3AdO9XGf6T4SCq7kz49hEEUwNvmkqR8Wxw&s=0%3Ajodv6q8w%3AHgkFFmKSZqdBB6E2C~F8xBKTHv8CGwbl&v=0%3AJ1gADq10d3pj1JL1lh4Dd7ZlLxQyl2~_&e=0%3AJ1gADq10d3pj1JL1lh4Dd7ZlLxQyl2~_0&c=jodvqubo&n=f&f=f&l=https%3A%2F%2Fwebsite.com%2F&i=11y&j=k8&k=1&w=mj&h=i9&t=pageView&x=-e1v043
It shows page not found error. What am I doing wrong? Is there some problem with regex or some other config problem?
If you want to use regex in a location directive you should add a tilde (~), but even then Location does not match the query string. Add /tracker/csc-event as a Location and check the query string inside that directive.
Also, proxypass preverses the query string, no need to add it.
This question already has an answer here:
why wamp server put online/ offline option is missing?
(1 answer)
Closed 6 years ago.
Whatever i do, cant acces local wamp through public ip adress.
I get following error message.
Forbidden
You don't have permission to access / on this server.
Apache/2.4.23 (Win64) PHP/5.6.25 Server at (my public ip) Port 80
Below i have pasted the part of httpd.cong that should regulate this.
Basically everything seems to be fine.
Wampserver is put online using its own menu item.
I have tried inserting below code into directory settings, does not help.
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
What am i missing ?
Thank you.
DocumentRoot "${INSTALL_DIR}/www"
<Directory "${INSTALL_DIR}/www/">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options +Indexes +FollowSymLinks +Multiviews
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride all
#
# Controls who can get stuff from this server.
#
# onlineoffline tag - don't remove
Require all granted
</Directory>
#RiggsFolly- if you have read my question, you woul dknow it is nowhere near to the one you have marked it being duplicate with.
I was not asking why the menu item is not visible...
Seems if you have an already made virtual host file, the put online menu item does not issue the necessary changes to it.
In the vhosts file Changing Require local to Require all granted fixed the issue.
Strange....
# Virtual Hosts
#
<VirtualHost *:80>
ServerName localhost
DocumentRoot F:/wamp64/www
<Directory "F:/wamp64/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
#
I use this command:
$ python manage.py collectstatic
to collect all static files from all applications and upload them to one single folder apps/apps/static/. So, I now have this file tree:
\home
\jacobian
\apps // <-- this is the root folder of my Django project
\apps
settings.py
urls.py
...
\static
The command collectstatic works fine - I see how it uploads all necessary files. But the problem is, I do not know how to force Apache now to load static files from that single \static folder. I tried to add these lines to my mysite.conf:
<VirtualHost *:80>
....
AliasMatch ^/js(.*) /home/jacobian/apps/apps/static$1
Alias /static/ /home/jacobian/apps/apps/static
</VirtualHost>
But is does not work. When I restart Apache and reload the page (which itself contains the link src="/js/test.js") in browser, I see in the console:
localhost/home/jacobian/apps/apps/static/js/test.js [HTTP/1.1 404 NOT FOUND]
although it seems that the url is resolved correctly, for some reason Apache is unable to upload static content from there. And by the way, what I also do not like about this is that the server discards home/jacobian/ part of the url.
EDIT
apache conf file looks like:
<VirtualHost *:80>
AliasMatch ^/js(.*) /home/jacobian/apps/apps/static$1
Alias /static/ /home/jacobian/apps/apps/static
DocumentRoot /home/jacobian/apps/apps
<Directory /home/jacobian/apps/apps/>
Order allow,deny
Allow from all
Options -Indexes
</Directory>
<Directory /home/jacobian/apps/apps/static>
Order allow,deny
Allow from all
</Directory>
WSGIScriptAlias / /home/jacobian/apps/apps/wsgi.py
</VirtualHost>
And this is what I have in Django project settings.py:
STATIC_URL = '/home/jacobian/apps/apps/static/'
STATIC_ROOT = '/home/jacobian/apps/apps/static/'
STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage'
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
EDIT
I also tried this configuration:
<VirtualHost *:80>
AliasMatch ^/js(.*) /home/jacobian/apps/apps/static$1
Alias /static/ /home/jacobian/apps/apps/static
WSGIScriptAlias / /home/jacobian/apps/apps/wsgi.py
<Directory /home/jacobian/apps/apps>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
</VirtualHost>
but still get the very same error localhost/static/js/test.js [HTTP/1.1 404 NOT FOUND], even though there is a file /home/jacobian/apps/apps/static/js/test.js. I have a guess that it might be somehow related to the DEBUG mode in settings.py. Maybe I should do some extra magic with urls.py?
First, change your STATIC_URL to: '/static/'. That should be URL on what Apache serves your static files, not system directory path.
Second, remove DocumentRoot from your apache config. All files outside of static directories should be handled by wsgi.
Third, change:
<Directory /home/jacobian/apps/apps/>
Order allow,deny
Allow from all
Options -Indexes
</Directory>
to:
<Directory /home/jacobian/apps/apps>
<Files wsgi.py>
Order allow,deny
Allow from all
</Files>
</Directory>
You don't want to serve all your files, just wsgi.py should be accessed publicly, and handled by WSGI. Also try to move that block below WSGIScriptAlias.
Fourth, remove trailing slash at the end of path in <Directory /home/jacobian/apps/apps/>.
Fifth, change allow,deny to deny,allow.
I have a Django application with the following directory structure
/myapp/
/login/
/myapp_settings/
/subapp1/
/supapp2/
manage.py is in the myapp directory.
In the project's url.py I have URL settings like this:
urlpatterns = patterns('',
url(r'^subapp1/', include('subapp1.urls')),
url(r'^xhr/', include('subapp1.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^subapp2/', include('smart_selects.urls')),
# Login / logout.
url(r'^login/$', 'django.contrib.auth.views.login'),
url(r'^logout/$', 'django.contrib.auth.views.logout', {'next_page': '/subapp1/'}, name='auth_logout'),
url(r'^logout/(?P<next_page>.*)/$', 'django.contrib.auth.views.logout', name='auth_logout_next'),
)
When deployed on the development runserver, everything links and loads correctly. When I deploy the entire myapp directory to the Django root on Apache, I find it's not linking as expected.
For example, if I link to example.com/login/, I get an Apache 404. I think it's because I don't have a virtual directory configuration defined for that specific directory.
I have the following set up in Apache for my application:
WSGIScriptAlias /myapp /var/www/django-projects/myapp/myapp_settings/wsgi.py
WSGIPythonPath /var/www/django-projects/myapp
Alias /media/ /var/www/django-projects/myapp/media/
Alias /static/ /var/www/django-projects/myapp/static/
<Directory /var/www/django-projects/myapp/static>
Order deny,allow
Allow from all
</Directory>
<Directory /var/www/django-projects/myapp/media>
Order deny,allow
Allow from all
</Directory>
<Directory /var/www/django-projects/myapp/myapp_settings/>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
Do I need an Alias and a Directory configuration for each URL pattern I use? If so, how can I redo my URL patterns so that I don't need to do this. I don't want to have to do all of this extra Apache configuration when I deploy the application.
EDIT: I modified my WSGIScriptAlias as suggest by Reinbach. It now reads WSGIScriptAlias / /var/www/django-projects/myapp/myapp_settings/wsgi.py. However, this still returns a 404. The error in the Apache log says
[Fri Sep 07 09:11:00 2012] [error] [client 192.189.x.x] File does not exist: /var/www/html/login
Notice that it's looking in /var/www/html (Default Apache root) instead of /var/www/django-projects
EDIT2: I'm attaching the VirtualHost block for this section
WSGIPythonPath /var/www/django-projects/myapp
<VirtualHost sub.example.com:80>
DocumentRoot /var/www/django-projects/myapp
ServerName sub.example.com
WSGIScriptAlias / /var/www/django-projects/myapp/myapp_settings/wsgi.py
Alias /robots.txt /var/www/django-projects/myapp/static/robots.txt
Alias /favicon.ico /var/www/django-projects/myapp/static/favicon.ico
AliasMatch ^/([^/]*\.css) /var/www/django-projects/myapp/static/css/$1
AliasMatch ^/([^/]*\.js) /var/www/django-projects/myapp/static/js/$1
AliasMatch ^/([^/]*\.png) /var/www/django-projects/myapp/static/images/$1
AliasMatch ^/([^/]*\.swf) /var/www/django-projects/myapp/static/swf/$1
Alias /media/ /var/www/django-projects/myapp/media/
Alias /static/ /var/www/django-projects/myapp/static/
<Directory /var/www/django-projects/myapp/static>
Order deny,allow
Allow from all
</Directory>
<Directory /var/www/django-projects/myapp/media>
Order deny,allow
Allow from all
</Directory>
<Directory /var/www/django-projects/myapp/myapp_settings/>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
</VirtualHost>
I believe you want to change your WSGIScriptAlias as you currently have it expecting to handle example.com/myapp/login while your sample is showing you trying to use example.com/login
WSGIScriptAlias / /var/www/django-projects/myapp/myapp_settings/wsgi.py
See How to use Django with Apache and mod_wsgi
LONG STORY SHORT
Allow and Deny are deprecated since Apache 2.4.x, use Require all granted (or denied) instead.
THE LONG STORY
I'm encountering the same problem while trying to set up Django with Apache and mod_wsgi. I'm not entirely sure why this happens but when I comment out the following lines in the httpd.conf
# Deny access to the entirety of your server's filesystem. You must
# explicitly permit access to web content directories in other
# <Directory> blocks below.
#
#<Directory />
# AllowOverride none
# Require all denied
#</Directory>
everything works alright.
I'm not sure if this is the right and secure way to solve the problem, but I hope it might help.
P.S. I think this shouldn't cause much security troubles since root directory is aliased anyways:WSGIScriptAlias / /var/www/django-projects/myapp/myapp_settings/wsgi.py, but I may be worng.
P.P.S. Looks like the better solution would be to leave those lines uncommented, but change Order and Allow directives in favor of Require all granted. For example:
<Directory /var/www/django-projects/myapp/myapp_settings/>
<Files wsgi.py>
Require all granted
#Order deny,allow
#Allow from all
</Files>
</Directory>
However this is only a trial and error solution I could come up. I got no deep understanding why it works but Order and Allow doesn't.
P.P.P.S Oh, now I know what. Allow and Deny are deprecated since Apache 2.4.x. Good answer can be found here.
My VHOST currently looks like:
<VirtualHost *:80>
DocumentRoot /data/sites/example_deploy
ServerName deploy.example.co.uk
<Directory "/data/sites/example_deploy">
Options +SymLinksIfOwnerMatch
AllowOverride All
Order allow,deny
Allow from all
AuthUserFile /data/confs/svn/htpasswd
AuthName "Example deployment example testing"
AuthType Basic
Require valid-user
</Directory>
</VirtualHost>
We have a URL /api that takes different parameters. Examples are:
/api/testing-bot-response/1234842823
/api/sql-deploy-response/stage/172bUd7s
What we are trying to achieve is that /api/* would not require a valid user and the HTaccess is satisfied before the request is made. The URL may be made up of more than 2 parameters.
I've researched the subject and have worked out that I need to use LocationMatch and pass the Satisfy parameter, however I am not sure how the regular expression should be formed.
I've resolved this issue. The trick is to use LocationMatch. Look at the below code:
$<LocationMatch "/api/*">
order allow,deny
allow from all
Satisfy any
</LocationMatch>