I have a ruby on rails application that is located at /home/user/application. I have a Apache webserver whose DocumentRoot is /var/www. And I have a symlink /var/www/application -> /home/user/application.
My apache configuration section that concerns the ruby on rails is the following:
RailsBaseURI /application
<Directory /home/user/application>
Order Allow,Deny
Allow from all
Options -MultiViews
</Directory>
I modified the Passenger code so in the very beginning of it spawning it would print (to a file) the option app_root. If it matters, I modified the file phusion_passenger/spawn_manager.rb in the method handle_spawn_application.
The value that I get is /home/user and this is wrong, I needed /home/user/application. So my question is, how does Passenger figures out the option['app_root'] (which becomes RAILS_ROOT|Rails.Root)?
Observation: I modified the Passenger code to hardcode app_root to /home/user/application and everything worked fine.
Change the symlink so that /var/www/application points to /home/user/application/public
Then just change RailsBaseURI to RackBaseURI and undo your changes to spawn_manager.rb
Previous discussion assumed single application.
<Directory /var/www/application/public>
Order Allow,Deny
Allow from all
Options -MultiViews
</Directory>
See the Apache Phusion documentation.
You need to add DocumentRoot and append /public to your Directory config and undo your changes to spawn_manager.rb.
As you noticed, the app_root is one directory up from what is specified.. The parent directory of /home/user/application/public is /home/user/application which is the Rails root.
You want RackBaseURI instead of RailsBaseURI for Rails > 3
The reasoning behind this is so that Apache serves the static assets (which are in the public directory) and then if that isn't present Passenger routes the request to the Rails app.
Related
I have a Debian server 9 with Apache 2 and Laravel 5.6
I have the folder: /LcmTI/projects/www to publish my projects, port 81 answers for all projects, eg:
http://localhost: 81/project1 [html project only]
In the folder /LcmTI/projects/laravel, I have two laravel projects 5.6:
extranet at /LcmTI/projects/laravel/extranet
intranet at /LcmTI/projects/laravel/intranet
I have created a link to the two projects in the www folder (which is the folder that is published):
ln -s /LcmTI/projects/laravel/extranet/public /LcmTI/projects/www/extranet
ln -s /LcmTI/projects/laravel/intranet/public /LcmTI/projects/www/intranet
In this way, I expected without any problem to access the two laravel environments without any problem, but it is not working.
When I type:
http://localhost:81/extranet/api/test or http://localhost:81/intranet/api/test
does not work and should return:
/* file routes/api.php in both applications */
`Route::get('test', function () {
return response()-> json(['foo' => 'bar']);
});`
If I enter http://localhost:81/extranet or http://localhost:81/intranet
Enter the homepage of Laravel
My configuration for Apache 2:
<VirtualHost *:81>
DocumentRoot /LcmTI/projects/www
<Directory /LcmTI/projects/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
Require all granted
</Directory>
</VirtualHost>
I'm having a hard time setting up larval API applications on a single host.
Let's say I have a directory on my site...
http://test.com/images/
...and I want to show a 403 forbidden error if somebody tries to access it. So I would use....
ErrorDocument 403 /403.shtml
...in the .htaccess file in my main directory. However, how could I make it so that it just displays the 403 error when the user is trying to view the directory directly. So if I wanted to visit...
http://test.com/images/test.png
...it would work and I could see the image, but if I visited http://test.com/images/, I would get a 403 error. How can I accomplish this?
Assuming you are using Apache, you should disable directory browsing in the config.
Find your httpd.conf (likely at /etc/apache/httpd.conf), and remove 'Indexes' from a line that will look like this:
Options Includes Indexes FollowSymLinks MultiViews
so that it looks like this:
Options Includes FollowSymLinks MultiViews
Then restart Apache.
BTW, that kind of question is better asked here instead:
https://webmasters.stackexchange.com/
I'm not only new to Laravel 4, but new to using frameworks. I thought I'd start with Laravel since it's gotten such good reviews.
I've got a good install of Laravel. I go to /l4/public and see the welcome page.
I'm trying to add a route to routes.php so that when I navigate to /l4/public/articles I get a response.
I get "The requested URL /l4/public/articles was not found on this server." Do I need to run an artisan command to compile the routes? It's probably something easy. Why this message?
routes.php
Route::get('/', function()
{
return View::make('hello');
});
Route::get('articles', function ()
{
//return View::make('articles');
return "Articles hello there";
});
Problem is solved by two editing changes in apache's httpd.conf file.
AllowOverride None is default. AllowOverride controls whether .htaccess files are processed.
mod_rewrite is commented out by default.
Changes to make:
Change 1: Activate mod_rewrite by uncommenting it.
Change 2:
Change
AllowOverride None
to
AllowOverride All
Now restart Apache...
The default .htaccess file that Laravel provides in the public folder specified some mod_rewrite rules. These rules were not getting applied because AllowOverride was set to none. Be sure and restart apache after changing these settings.
My configuration: Apache 2.4.6 on Windows XP.
It appears that there may be some security implications to the AllowOverride change. If anyone has additional information on this, I would like to hear it.
That Error basically say that the router cannot found your request. Make sure you already save your changes.
if you using the artisan command to running the page,just re-run again command "artisan Serve".
You need mod_rewrite on. Try: l4/public/index.php/articles
in httpd.conf change
<Directory />
AllowOverride none
Require all granted
</Directory>
to
<Directory />
AllowOverride all
Require all granted
</Directory>
then uncomment
#LoadModule rewrite_module modules/mod_rewrite.so
to
LoadModule rewrite_module modules/mod_rewrite.so
I'm writing a script to build a dynamic website,
the website is created by loading external components.
The DocumentRoot is location at /sites/website/public
the components directory is located at /sites/website/components
i wannna reach the data directory of each component depends on the requested url.
for example:
the url:
http://ibuildmywebsite/component-data/randomimage/demo/swan04090044_small.jpg
should fetch the file /sites/website/components/randomimage/data/demo/swan04090044_small.jpg
how can i achieve that ?
i would prefer a way that can be placed inside .htaccess (if there is one) instead of modifying the virtual host definitions.
Thanks!
Combine RewriteRule with Alias maybe ?
Alias /randomimage /sites/website/components/randomimage
RewriteRule ^component-(.*)/randomimage/(.*)$ /randomimage/$1/$2 [R,L]
(Won't work in .htaccess though)
You could probably also use Symlinks with:
Options +FollowSymLinks
And link dynamically components-*/randommimage/* to /sites/website/components/randomimage/*/*/
I have Windows XP/Django/apache/mod_python working on localhost. All parts are working with the exception of the admin CSS not rendering. The admin works, but no html formatting. I've made additions in:
settings.py
INSTALLED_APPS
'django.contrib.admin',
urls.py
from django.contrib import admin
admin.autodiscover()
(r'^admin/(.*)', admin.site.root),
conf/http.conf
<Location "/">
SetHandler python-program
PythonPath "['C:/django'] + sys.path"
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
PythonDebug On
</Location>
<Location "/cpssite/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE myapplication.settings
PythonInterpreter /myapplication
PythonDebug On
</Location>
I'm stumped. Is there more code I should have added somewhere?
Does your ADMIN_MEDIA_PREFIX exist? Is it different from MEDIA_URL? Did you include the trailing slash? Is Apache handled to correctly serve up the admin media?
The default Django configuration has the admin media located at {Django install dir}/contrib/admin/media. ADMIN_MEDIA_PREFIX defaults to /media/. So you need to add something like this to your Apache config:
Alias /media/ /path/to/django/contrib/admin/media/
This will tell Apache that requests for mysite.com/media/css/whatever.css mean to serve up /path/to/django/contrib/admin/media/css/whatever.css, which should solve your issue.
I used to have the same problem and the following entry in the http.conf worked fine with me:
<Directory "Path-to-python/Lib/site-packages/django/contrib/admin/media/">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
Alias /media/ "Path-to-Python/Lib/site-packages/django/contrib/admin/media/"
<Location "/mysite/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
PythonOption django.root /mysite
PythonInterpreter mysite
PythonDebug On
PythonPath "['C:/Python/Django/apps'] + sys.path"
</Location>
Here is my django-specific apache configuration. Note, django handles every incoming url to the site (location /) except media, where it's disabled, and the data is served from django's media directory.
<Location "/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
#PythonOption django.root /
PythonDebug On
PythonPath "['e:/dj'] + sys.path"
</Location>
Alias /media e:/dj/django-trunk/django/contrib/admin/media/
<Location "/media">
SetHandler None
</Location>
If you don't want to have admin media use the /media directory, you can specify ADMIN_MEDIA_PREFIX = 'admin_media', then create a link/alias from your webserver which redirects calls to /admin_media/ to the /usr/share/pyshared/django/contrib/admin/media (depending on your OS) for your production server...
Since the question is from long time back, this may not be a relevant answer but I am putting this information to help anyone who happens to stumble here just like me.
As of version 1.4, ADMIN_MEDIA_PREFIX setting has been deprecated. The ways of serving static and media files with version >= 1.4 are described here
https://docs.djangoproject.com/en/dev/releases/1.4/#django-contrib-admin
https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/modwsgi/#serving-files
https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/modwsgi/#serving-the-admin-files
Basically it can be setup in 4 steps -
Set STATIC_ROOT to point to directory which will serve all the static files of your site
Set STATIC_URL for which static content should be served
Run manage.py collectstatic
Configure your webserver to serve requests for STATIC_URL from STATIC_ROOT
Same for media files