Uploads static file to directory and then server with apache...

classic Classic list List threaded Threaded
18 messages Options
Reply | Threaded
Open this post in threaded view
|

Uploads static file to directory and then server with apache...

webmediauk
Hey,
I've got a model with a static file asoociated to it. For speed I upload the file to a sub-directory of a directory and then serve the file up with apache:
This is the line of code in question within my controller:

uploadedFile.transferTo( new File( userDir, uploadedFile.originalFilename))

The code works and uploads the file but then apache won't serve it up. The permissions are different on the file once its uploaded (obviously the owner is "tomcat"). To get the file to be accessible I have to delete it and manually upload the file as ROOT!
Does anyone know if this would be an apache issue or a grails issue?
My bet is on apache but if anyone can see the problem please let me know.
Many Thanks
Baz
Reply | Threaded
Open this post in threaded view
|

Re: Uploads static file to directory and then server with apache...

tkauppin
Sounds like *nix filesystem permission problem

Most likely Tomcat is run by user tomcat and apache by apache or httpd

if you do something like "ls -ltr", what are the permission on the newly created file? Likely to be something like
rwxr----- (~740)

if so you have to
a) add the user used to run apache to the tomcat-group in /etc/group
b) change the default file permissions of new files for tomcat user by using 'umask'
Reply | Threaded
Open this post in threaded view
|

Re: Uploads static file to directory and then server with apache...

webmediauk
When I do "ls -ltr" on the newly created file I get this:

total 16
-rw-r--r--. 1 tomcat tomcat 14294 Oct 18 10:41 UKSG-70x82.png


I have changed this line in /etc/group:

apache:x:48:

to this:

apache:x:48:tomcat

And restart apache.
Still doesn't work :(
Does that give you anymore clues to resolving the issue?

Many Thanks
Barry
Reply | Threaded
Open this post in threaded view
|

Re: Uploads static file to directory and then server with apache...

webmediauk
Further more to this. If I look at the file permissions and group/owner etc on the newly updated file:

Permissions are the same as a file uploaded by root.
Group and Owner are different but if I manually change them to root the file is still not accessible via apache.


Only when I delete and re-upload the file via FTP as root does it become accessible via apache?
This suggests to me that it is not a file permissions issue?
Reply | Threaded
Open this post in threaded view
|

Re: Uploads static file to directory and then server with apache...

webmediauk
I am still facing this bug! Have spent all afternoon trying to figure this one out but have a bit more information. If the file I'm uploading is under 10Kb it copies fine and is viewable in apache, if it's over 10Kb the entire file is copied but is not viewable in apache???
Anyone have any ideas on this please?
Reply | Threaded
Open this post in threaded view
|

Re: Uploads static file to directory and then server with apache...

sergiomichels
You configured a virtual directory for the images, or this is inside your grails app?

--
Sérgio Michels


On Mon, Jan 7, 2013 at 4:41 PM, webmediauk <[hidden email]> wrote:
I am still facing this bug! Have spent all afternoon trying to figure this
one out but have a bit more information. If the file I'm uploading is under
10Kb it copies fine and is viewable in apache, if it's over 10Kb the entire
file is copied but is not viewable in apache???
Anyone have any ideas on this please?



--
View this message in context: http://grails.1312388.n4.nabble.com/Uploads-static-file-to-directory-and-then-server-with-apache-tp4636195p4639870.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: Uploads static file to directory and then server with apache...

webmediauk
In reply to this post by webmediauk
Hey, yeh I've got an apache virtual host set up and grails uploads the files into the document root.
Thanks

----- Reply message -----
From: "Sergio Michels" <[hidden email]>
To: <[hidden email]>
Subject: [grails-user] Re: Uploads static file to directory and then server with apache...
Date: Mon, Jan 7, 2013 7:38 pm


You configured a virtual directory for the images, or this is inside your grails app?

--
Sérgio Michels


On Mon, Jan 7, 2013 at 4:41 PM, webmediauk <[hidden email]> wrote:
I am still facing this bug! Have spent all afternoon trying to figure this
one out but have a bit more information. If the file I'm uploading is under
10Kb it copies fine and is viewable in apache, if it's over 10Kb the entire
file is copied but is not viewable in apache???
Anyone have any ideas on this please?



--
View this message in context: http://grails.1312388.n4.nabble.com/Uploads-static-file-to-directory-and-then-server-with-apache-tp4636195p4639870.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: Uploads static file to directory and then server with apache...

sergiomichels
In reply to this post by webmediauk
Ok, can you post your config? What's the http status code that you receive when trying to access the virstual host?

--
Sérgio Michels


On Mon, Jan 7, 2013 at 5:56 PM, Barry Antrobus <[hidden email]> wrote:
Hey, yeh I've got an apache virtual host set up and grails uploads the files into the document root.
Thanks


----- Reply message -----
From: "Sergio Michels" <[hidden email]>
To: <[hidden email]>
Subject: [grails-user] Re: Uploads static file to directory and then server with apache...
Date: Mon, Jan 7, 2013 7:38 pm


You configured a virtual directory for the images, or this is inside your grails app?

--
Sérgio Michels


On Mon, Jan 7, 2013 at 4:41 PM, webmediauk <[hidden email]> wrote:
I am still facing this bug! Have spent all afternoon trying to figure this
one out but have a bit more information. If the file I'm uploading is under
10Kb it copies fine and is viewable in apache, if it's over 10Kb the entire
file is copied but is not viewable in apache???
Anyone have any ideas on this please?



--
View this message in context: http://grails.1312388.n4.nabble.com/Uploads-static-file-to-directory-and-then-server-with-apache-tp4636195p4639870.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email




Reply | Threaded
Open this post in threaded view
|

Re: Uploads static file to directory and then server with apache...

webmediauk
In reply to this post by webmediauk
I'll post the config in the morning. I get a 403 when trying to access the newly uploaded file.
Thanks

----- Reply message -----
From: "Sergio Michels" <[hidden email]>
To: <[hidden email]>
Subject: [grails-user] Re: Uploads static file to directory and then server with apache...
Date: Mon, Jan 7, 2013 8:01 pm


Ok, can you post your config? What's the http status code that you receive when trying to access the virstual host?

--
Sérgio Michels


On Mon, Jan 7, 2013 at 5:56 PM, Barry Antrobus <[hidden email]> wrote:
Hey, yeh I've got an apache virtual host set up and grails uploads the files into the document root.
Thanks


----- Reply message -----
From: "Sergio Michels" <[hidden email]>
To: <[hidden email]>
Subject: [grails-user] Re: Uploads static file to directory and then server with apache...
Date: Mon, Jan 7, 2013 7:38 pm


You configured a virtual directory for the images, or this is inside your grails app?

--
Sérgio Michels


On Mon, Jan 7, 2013 at 4:41 PM, webmediauk <[hidden email]> wrote:
I am still facing this bug! Have spent all afternoon trying to figure this
one out but have a bit more information. If the file I'm uploading is under
10Kb it copies fine and is viewable in apache, if it's over 10Kb the entire
file is copied but is not viewable in apache???
Anyone have any ideas on this please?



--
View this message in context: http://grails.1312388.n4.nabble.com/Uploads-static-file-to-directory-and-then-server-with-apache-tp4636195p4639870.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email




Reply | Threaded
Open this post in threaded view
|

Re: Uploads static file to directory and then server with apache...

webmediauk
Hey,
Here's my vhost setup:

<VirtualHost xx.xx.xx.xx>
    Options FollowSymLinks MultiViews
    ServerAdmin webmaster@xx.co.uk
    DocumentRoot /var/www/static/
    ServerName static.xx.co.uk
    <Directory /var/www/static>
      Options +Indexes
    </Directory>
</VirtualHost>

Apache is running as user apache.
Can you shed any light on this please? I'm out of ideas!
Thanks
Barry
Reply | Threaded
Open this post in threaded view
|

Re: Uploads static file to directory and then server with apache...

wavyx
Could you also tell:
- where are your files located ?
- what is their mode and ownership (ls -la) ?
- do you have a controller accessing the file and returning the bytes, or do you try to use some "direct access" to files

Eric


On Tue, Jan 8, 2013 at 10:02 AM, webmediauk <[hidden email]> wrote:
Hey,
Here's my vhost setup:

<VirtualHost xx.xx.xx.xx>
    Options FollowSymLinks MultiViews
    ServerAdmin [hidden email]
    DocumentRoot /var/www/static/
    ServerName static.xx.co.uk
    <Directory /var/www/static>
      Options +Indexes
    </Directory>
</VirtualHost>

Apache is running as user apache.
Can you shed any light on this please? I'm out of ideas!
Thanks
Barry




--
View this message in context: http://grails.1312388.n4.nabble.com/Uploads-static-file-to-directory-and-then-server-with-apache-tp4636195p4639892.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: Uploads static file to directory and then server with apache...

webmediauk
Hey Eric,
- where are your files located ?
The files are uploaded by the grails app to a path on the app server (CentOS).

- what is their mode and ownership (ls -la) ?
-rw-r--r--.   1 tomcat tomcat 3984 Jan  7 16:53 70x8224.png
That's an example


- do you have a controller accessing the file and returning the bytes, or do you try to use some "direct access" to files?
Direct access: the path where the files are uploaded is also the document root for an Apache virtual host. So Apache serves the files.

Hope that helps, and thanks for your help.
Barry
Reply | Threaded
Open this post in threaded view
|

Re: Uploads static file to directory and then server with apache...

wavyx
Hi,

maybe compare the mode / ownership of files accessible and not accessible.

For ex, you could try to fir the ownership of your uploaded files 
chown apache:apache 70x8224.png

Since it's a direct access, apache error log should be a good place to look.

++
Eric


On Tue, Jan 8, 2013 at 3:20 PM, webmediauk <[hidden email]> wrote:
Hey Eric,
- where are your files located ?
*The files are uploaded by the grails app to a path on the app server
(CentOS).*

- what is their mode and ownership (ls -la) ?
*-rw-r--r--.   1 tomcat tomcat 3984 Jan  7 16:53 70x8224.png
That's an example*

- do you have a controller accessing the file and returning the bytes, or do
you try to use some "direct access" to files?
*Direct access: the path where the files are uploaded is also the document
root for an Apache virtual host. So Apache serves the files.*

Hope that helps, and thanks for your help.
Barry



--
View this message in context: http://grails.1312388.n4.nabble.com/Uploads-static-file-to-directory-and-then-server-with-apache-tp4636195p4639916.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: Uploads static file to directory and then server with apache...

webmediauk
Thanks for your help Eric,
I have previously compared ownership and group as you said.
When a file is uploaded, it is tomcat : tomcat.
If I then change it to root : root or apache : apache it is still inaccessible.
If I overwrite the file as root via ssh the file is still not accessible.
If I remove the file and then upload it via ssh as root the file IS accessible!
The error in the apache log is the same everytime:

[Tue Jan 08 16:21:30 2013] [error] [client xx.xxx.xx.xxx] (13)Permission denied: access to /creatives/19243/IC728x90.gif denied

Many Thanks
Barry
Reply | Threaded
Open this post in threaded view
|

Re: Uploads static file to directory and then server with apache...

webmediauk
In reply to this post by wavyx
Thanks for your help Eric,
I have previously compared ownership and group as you said.
When a file is uploaded, it is tomcat : tomcat.
If I then change it to root : root or apache : apache it is still inaccessible.
If I overwrite the file as root via ssh the file is still not accessible.
If I remove the file and then upload it via ssh as root the file IS accessible!
The error in the apache log is the same everytime:

[Tue Jan 08 16:21:30 2013] [error] [client xx.xxx.xx.xxx] (13)Permission denied: access to /creatives/19243/IC728x90.gif denied

Many Thanks
Barry
Reply | Threaded
Open this post in threaded view
|

Re: Uploads static file to directory and then server with apache...

wavyx
In reply to this post by webmediauk
Looks like an apache user group question.
But I would suggest these:

my best guess would be "Make sure that the Directory Above has Execute Permission" (or "Make sure Apache has Read, Execute Permissions")


On Tue, Jan 8, 2013 at 3:20 PM, webmediauk <[hidden email]> wrote:
Hey Eric,
- where are your files located ?
*The files are uploaded by the grails app to a path on the app server
(CentOS).*

- what is their mode and ownership (ls -la) ?
*-rw-r--r--.   1 tomcat tomcat 3984 Jan  7 16:53 70x8224.png
That's an example*

- do you have a controller accessing the file and returning the bytes, or do
you try to use some "direct access" to files?
*Direct access: the path where the files are uploaded is also the document
root for an Apache virtual host. So Apache serves the files.*

Hope that helps, and thanks for your help.
Barry



--
View this message in context: http://grails.1312388.n4.nabble.com/Uploads-static-file-to-directory-and-then-server-with-apache-tp4636195p4639916.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: Uploads static file to directory and then server with apache...

sergiomichels
In reply to this post by webmediauk
What happens if you change the config to:

<VirtualHost xx.xx.xx.xx>
    Options FollowSymLinks MultiViews
    ServerAdmin [hidden email]
    DocumentRoot /var/www/static/
    ServerName static.xx.co.uk
    <Directory /var/www/static>
      Options +Indexes
    Order allow,deny
    Allow from all
    </Directory>
</VirtualHost>

--
Sérgio Michels


On Tue, Jan 8, 2013 at 2:17 PM, webmediauk <[hidden email]> wrote:
Thanks for your help Eric,
I have previously compared ownership and group as you said.
When a file is uploaded, it is tomcat : tomcat.
If I then change it to root : root or apache : apache it is still
inaccessible.
If I overwrite the file as root via ssh the file is still not accessible.
If I remove the file and then upload it via ssh as root the file *IS*
accessible!
The error in the apache log is the same everytime:

*[Tue Jan 08 16:21:30 2013] [error] [client xx.xxx.xx.xxx] (13)Permission
denied: access to /creatives/19243/IC728x90.gif denied*

Many Thanks
Barry



--
View this message in context: http://grails.1312388.n4.nabble.com/Uploads-static-file-to-directory-and-then-server-with-apache-tp4636195p4639935.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: Uploads static file to directory and then server with apache...

webmediauk
Hurray! I've figured it out!
Thanks for all your help Eric, I did try the config change but it made no difference. Turns out this OS feature!

http://stackoverflow.com/questions/1225594/apache-13-permission-denied-in-users-home-directory

All sorted now anyway.
Thanks again.