Re: [mezzanine-users] tinymce - nginx - 404 problem

1,855 views
Skip to first unread message

Sal Lara

unread,
Jun 27, 2012, 9:10:27 AM6/27/12
to mezzani...@googlegroups.com
Can you post more of your nginx conf file? On my conf file, I don't specify the media directory. You shouldn't have to (folks please correct me if I'm wrong), because static is mapped and is its parent.

Here's mine:

worker_processes 1;

user nobody nogroup;
pid /tmp/nginx.pid;
error_log /tmp/nginx.error.log;

events {
    worker_connections 1024;
    accept_mutex off;
}

http {
    include mime.types;
    default_type application/octet-stream;
    access_log /tmp/nginx.access.log combined;
    sendfile on;

    upstream app_server {
        #        server unix:/tmp/gunicorn.sock fail_timeout=0;
        # For a TCP configuration:
        server 127.0.0.1:8888 fail_timeout=0;
    }

    server {
        listen 80;
        client_max_body_size 4G;
        server_name www.mysite.com;

        keepalive_timeout 5;

        location /static {
            root /depot/pal/myproject;
        }

        location / {
            proxy_pass http://127.0.0.1:8888;
        }
    }
}

Cheers,
-Sal

On Wed, Jun 27, 2012 at 7:36 AM, spoty <spot...@gmail.com> wrote:
Hello guys, I need your help :)

I run my mezzanine project on gunicorn and nginx (is serving static files).
I have problem with tinymce,
for Insert/Edit Image, Insert/Edit Embedded Image,and so on I am getting 404 Not found nginx/1.1.19.

My nginx.conf

  location /media {
  root   /home/user/sites/mysite/static/;
}

  location /static {
  root   /home/user/sites/mysite/;
    }


I don't know why, it's trying to reach:

http://10.41.142.137/static_proxy/?u=http://10.41.142.137/static/grappelli/tinymce/jscripts/tiny_mce/plugins/advimage/image.htm    =   404

http://10.41.142.137/static/grappelli/tinymce/jscripts/tiny_mce/plugins/advimage/image.htm = It's  OK

Everything else is working right.

I am a begginer, pls have patient with me :) thank you in advance.

Martin





spoty

unread,
Jun 27, 2012, 9:40:48 AM6/27/12
to mezzani...@googlegroups.com
Hi Sal, thank you for your time.

My nginx.conf :
user user;
worker_processes 4;
pid /home/user/sites/nginx.pid;

events {
    worker_connections 768;

}

http {



    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;


    include /etc/nginx/mime.types;
    default_type application/octet-stream;



    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;



    gzip on;
    gzip_disable "msie6";



    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}


spoty

unread,
Jun 27, 2012, 9:42:31 AM6/27/12
to mezzani...@googlegroups.com
sites-enabled:

server {
 listen   80;
 server_name  mysite;
 access_log  /home/user/sites/mysite/logs/access.log;
 error_log  /home/user/sites/mysite/logs/error.log debug;

 #set your default location
 location / {
  proxy_pass         http://localhost:8000/;

Sal Lara

unread,
Jun 27, 2012, 12:54:00 PM6/27/12
to mezzani...@googlegroups.com
I think you may want to drop the trailing forward-slash on both locations' root paths.

Try removing that. Also again, I don't think you need to define media and static. As long as media is defined as relative to static in your settings.py, mapping your static directory in the nginx conf is enough.

Martin Rajnoha

unread,
Jun 28, 2012, 4:14:52 AM6/28/12
to mezzani...@googlegroups.com
Thank you Sal for respond.

 I tried to remove forward-slash on location-root path for static files and also deleted path for media, but nothing happend.

Status:
Every static file is working right.
Just tinymce pop up windows = 404 Not Found.

Is it not a problem when we say nginx that static files are /static/

and then we link to htm files?

/static/grappelli/tinymce/jscripts/tiny_mce/plugins/advimage/image.htm 
 
Thank you in advance.

Martin

Martin Rajnoha

unread,
Jun 28, 2012, 4:24:55 AM6/28/12
to mezzani...@googlegroups.com
I thnik problem can be with

mezzanine.core.views.static_proxy(request, *args, **kwargs)

Serves TinyMCE plugins inside the inline popups and the uploadify SWF, as these are normally static files, and will break with cross-domain JavaScript errors if STATIC_URL is an external host. URL for the file is passed in via querystring in the inline popup plugin template.

But I cant idetify a problem here by myself.

Thanks

Martin

Martin Rajnoha

unread,
Jun 28, 2012, 5:00:59 AM6/28/12
to mezzani...@googlegroups.com
OK, so I was able to fix this.

What I did is that I removed static_proxy from views and urls, but I am not quite sure if this is correct solution.

  •     url("^static_proxy/$", "static_proxy", name="static_proxy"),       
  • @staff_member_required
    def static_proxy(request):

  •     """
        Serves TinyMCE plugins inside the inline popups and the uploadify
        SWF, as these are normally static files, and will break with
        cross-domain JavaScript errors if ``STATIC_URL`` is an external
        host. URL for the file is passed in via querystring in the inline
        popup plugin template.
        """
  •     # Get the relative URL after STATIC_URL.
        url = request.GET["u"]
        protocol = "http" if not request.is_secure() else "https"
        host = protocol + "://" + request.get_host()
        for prefix in (host, settings.STATIC_URL):
            if url.startswith(prefix):
                url = url.replace(prefix, "", 1)
        response = ""
        path = finders.find(url)
        if path:
            if isinstance(path, (list, tuple)):
                path = path[0]
            with open(path, "rb") as f:
                response = f.read()
            mimetype = "application/octet-stream"
            if url.endswith(".htm"):
                # Inject <base href="{{ STATIC_URL }}"> into TinyMCE
                # plugins, since the path static files in these won't be
                # on the same domain.
                mimetype = "text/html"
                static_url = settings.STATIC_URL + os.path.split(url)[0] + "/"
                base_tag = "<base href='%s'>" % static_url
                response = response.replace("<head>", "<head>" + base_tag)
        return HttpResponse(response, mimetype=mimetype)

Brian Schott

unread,
Jun 28, 2012, 10:54:04 AM6/28/12
to mezzani...@googlegroups.com
That's fine if you are running a single server configuration, but it means you'll have to back port any updates to your custom version.  I hit a similar issue because I was running https on the proxy and not forwarding the security headers appropriately (runserver breaks and gunicorn takes them).  So the proxy was going to http rather than https.  You can see my configuration in https://github.com/stephenmcd/mezzanine/issues/269.  That configuration posted there works if you take out the SSL/443 references.

You really must have a configuration issue somewhere to be hitting this.  It is probably one of two things:

1. Can you reach the URL passed to the proxy call directly from your browser?  
     If you can't reach http://example.com/static/grappelli/tinymce/jscripts/tiny_mce/plugins/table/table.htm from a browser, then mezzanine and django are not involved.  It must be an nginx config.  My guess is that you are browsing to your site using a virtual hostname, but that hostname isn't in your sites table and the proxy redirect is using IP address or the wrong hostname for your nginx config.

2. Do you get a directory error with:
http://example.com/static_proxy/?u=/static/
  "[Errno 21] Is a directory"
   If not, then the proxy is probably not in URLs list somehow or the STATIC_FILES setup is configured wrong:

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
    "django.contrib.staticfiles.finders.FileSystemFinder",
    "django.contrib.staticfiles.finders.AppDirectoriesFinder",
#    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

# URL prefix for static files.
STATIC_URL = "/static/"

# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = os.path.join(PROJECT_ROOT, STATIC_URL.strip("/"))

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
MEDIA_URL = STATIC_URL + "media/"

# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = os.path.join(PROJECT_ROOT, *MEDIA_URL.strip("/").split("/"))


Brian

Martin Rajnoha

unread,
Jun 29, 2012, 3:38:25 AM6/29/12
to mezzani...@googlegroups.com
Hi Brian, thank you for interest.

So I run my ubuntu server in VirtualBox, network over bridge with internal IP 192.168.0.14

1. whe I request http://192.168.0.14/static_proxy/?u=http://192.168.0.14/static/grappelli/tinymce/jscripts/tiny_mce/plugins/advimage/image.htm
respond is 404

If I try just http://192.168.0.14/static/grappelli/tinymce/jscripts/tiny_mce/plugins/advimage/image.htm
its working.

2. http://192.168.0.14/static_proxy/?u=/static/  
  respond 404

http://192.168.0.14/static/
respond 403

Thats all I can say for now, I will try to digg in it more during weekend.
Tahnk for help guys I appreciate it.

Martin

Stephen McDonald

unread,
Jun 29, 2012, 8:55:57 AM6/29/12
to mezzani...@googlegroups.com
Sorry I haven't followed this thread properly, but just though I'd give some context around what the static_proxy URL is for.

There's a handful of files particularly with TinyMCE that get referenced as iframes, one of those being the image.htm file mentioned. If your static files are hosted on a separate host, you'll end up with a bunch of cross-domain security errors when trying to use TinyMCE. I believe the Flash widget for uploading files in filebrowser was another example of this. So any files like that get passed onto the static_proxy url/view, which simply reads the "u=" param and serves up the file from the same host the site is running on, to avoid cross-domain security errors.

If you aren't using a separate host, and get around an issue you're having by pulling out the static_proxy setup, then great. But you've probably uncovered a bug in the static_proxy code which would be nice to resolve. Also if anyone has a better solution to this, I'd love to get rid of the static_proxy feature.
--
Stephen McDonald
http://jupo.org

Matt Cooper

unread,
Jul 19, 2012, 6:30:55 AM7/19/12
to mezzani...@googlegroups.com
Hi all

I'm having this problem witht he MCE images and the uploadify, so clearly got the same /static_proxy/ issue.

I'm hosting this app on dotcloud (who use nginx too) and can override the conf as far as I'm aware. Not used it before so all a bit new though.

I can't get static_proxy to return anything at the moment and don't know where the problem is.

Any experience of using the static_proxy feature much appreciated.

Matt

Matt Cooper

unread,
Jul 19, 2012, 12:23:56 PM7/19/12
to mezzani...@googlegroups.com
I've stripped out django-storages and tested it locally and it works fine...

Then deployed to dotcloud and it doesn't.... I've asked them too.

so favourite is the nginx config so am reading about that. Is just the static_proxy URLs that aren't working, everything else is fine. 

Will start looking at the static_proxy code now.

Matt Cooper

unread,
Jul 20, 2012, 11:10:49 AM7/20/12
to mezzani...@googlegroups.com

Just realised that a site on webfaction works, but this is using 1.0.8 and this functionality wasn't in that version. May have to go back a version but want to use S3 for static files and remote files is what this was put in for....

Matt Cooper

unread,
Jul 25, 2012, 5:24:02 AM7/25/12
to mezzani...@googlegroups.com
Update on this problem.

Ken at dotcloud has found that there was a bug in their global nginx conf file that was causing the static_proxy URL to be handled incorrectly. It will be fixed with the next release of their software.

In the interim I need to get it working.
One way would be to override the name of the function so it doesn't include  "static" which should then work. I'm looking at how much work this would take, any thoughts appreciated.

Matt

Stephen McDonald

unread,
Jul 25, 2012, 4:57:26 PM7/25/12
to mezzani...@googlegroups.com
So they match anything with /static/ in it?

Matt Cooper

unread,
Jul 25, 2012, 5:01:42 PM7/25/12
to mezzani...@googlegroups.com, st...@jupo.org
Hi Stephen
Yes! Missing trailing / :)

Matt

Stephen McDonald

unread,
Jul 25, 2012, 5:21:39 PM7/25/12
to mezzani...@googlegroups.com
Ok just pushed up a change that lets you set the URL yourself:


(will appear on GitHub once it stop timing out, but I have to leave right now)

So in settings.py

STATIC_PROXY_URL = "foo"

Matt Cooper

unread,
Jul 25, 2012, 7:09:26 PM7/25/12
to mezzani...@googlegroups.com, st...@jupo.org
Hi Stephen

MANY thanks for doing that :)

I've just tried it and getting the same error with my new URL! It's late and it's probably me.

I've put the setting in my settings.py

STATIC_PROXY_URL = "really"

Then added the url pattern in my root urls.py thus:

url("^%s/$" % _proxy_url, "static_proxy", name="static_proxy"),
("^", include("mezzanine.urls")),

Was hoping this would override the original but it doesn't seem to work and if I loop through all the urls in a shell I see both..

So the only way I can think to do it is to take out the include mezzanine.urls, manually include all the other url files except the core one and then put the modified core urls in my urls.py but this doesn’t sound very elegant.

So question is how do I override just that URL in a better way?

Matt

Stephen McDonald

unread,
Jul 25, 2012, 7:27:31 PM7/25/12
to mezzani...@googlegroups.com
Did you pull the latest change?

Adding the urlpattern manually won't work.

Matt Cooper

unread,
Jul 25, 2012, 7:31:45 PM7/25/12
to mezzani...@googlegroups.com, st...@jupo.org

Hi Stephen

no figured adding the url is not the way to go.

As I'm using dotcloud the environment is getting built when I push the app via pip so I'm getting the 1.1.4 release.

Unsure how to override it with the change.

M

Stephen McDonald

unread,
Jul 25, 2012, 7:33:58 PM7/25/12
to mezzani...@googlegroups.com
Ok well the change only exists in GitHub and BitBucket at the moment.

1.2 is more or less ready to release - probably this weekend.

Matt Cooper

unread,
Jul 25, 2012, 7:41:21 PM7/25/12
to mezzani...@googlegroups.com, st...@jupo.org
Hi Stephen

Yes, I can wait if it's coming soon.

I'm assuming it's possible to programatically manipulate the urls once the list has been built at startup? Not worth it though in this case as it will be fixed shortly.

Thanks for adding this functionality, you have beaten dotcloud to it :)

Matt

Stephen McDonald

unread,
Jul 25, 2012, 7:43:21 PM7/25/12
to mezzani...@googlegroups.com
Yes it's probably possible, not recommended :-)

I'll actually probably undo that setting I added and rename the prefix in the urlpattern to something other than static - the only case it solves is conflicting with /static/

Matt Cooper

unread,
Jul 25, 2012, 7:50:09 PM7/25/12
to mezzani...@googlegroups.com, st...@jupo.org
Hi Stephen

Yes I will resist the urge to hack :)

The dotcloud issue is just because the master nginx config matches static* and maps it to their static folders. So if you change it to anything else it will work fine.

Matt

nathan

unread,
Oct 23, 2012, 11:13:30 AM10/23/12
to mezzani...@googlegroups.com
I am having trouble with the files mentioned here.  It seems to me there is in fact something wrong with my nginx.conf file.  But I am using FastCGI so I'm not sure how to adjust.  All I know is that I can't insert an image with tinymce, and I can't serve the grappelli files that are involved with iframe as Stephen mentioned.  All other admin files are fine.  Is this an issue with my nginx.conf?

Here is the nginx.conf

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local]' '"$request"              
                      $status $body_bytes_sent' '"$http_referer"                           
                      "$http_user_agent" "$http_x_forwarded_for"'
                      '"$gzip_ratio"';

    client_header_timeout       10m;
    client_body_timeout         10m;
    send_timeout                10m;

    access_log  /var/log/nginx/access.log  main;

    connection_pool_size                   256;
    client_header_buffer_size              1k;
    large_client_header_buffers            4 2k;
    request_pool_size                      4k;

    sendfile        on;
    tcp_nopush     on;
    tcp_nodelay    on;


    keepalive_timeout  75 20;

    gzip  on;
    gzip_min_length     1100;
    gzip_buffers        4 8k;
    gzip_types          text/plain;

    output_buffers      1 32k;
    postpone_output     1460;

    ignore_invalid_headers      on;
    index index.html;

    #                                                                                      
    # The default server                                                                   
    #                                                                                      
    server {
        listen       80;
        server_name  127.0.0.1;

        root /home/ec2-user/alhandcrafts/;

        location /static/ {
                 alias /home/alhandcrafts/static/;
                 }

        location ~*^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|tx\
t|tar|mid|midi|wav|bmp|rtf|js|mov){
         access_log     off;
         expires        30d;
         }


        location / {
                 fastcgi_pass 127.0.0.1:8080;
                 fastcgi_param PATH_INFO $fastcgi_script_name;
                 fastcgi_param REQUEST_METHOD $request_method;
                 fastcgi_param QUERY_STRING $query_string;
                 fastcgi_param CONTENT_TYPE $content_type;
                 fastcgi_param CONTENT_LENGTH $content_length;
                 fastcgi_pass_header Authorization;
                 fastcgi_intercept_errors off;                                             \
     fastcgi_param SERVER_PROTOCOL $server_protocol;
                 fastcgi_param SERVER_PORT $server_port;
                 fastcgi_param SERVER_NAME $server_name;
                 fastcgi_param REMOTE_ADDR $remote_addr;
           }
                                                                                        acc\
ess_log      /var/log/nginx/localhost.access_log main;
         error_log       /var/log/nginx/localhost.error_log;
                 }
                                                                                           \
                                                                 
Thanks,
Nate




On Wednesday, June 27, 2012 8:35:06 AM UTC-4:1, spoty wrote:
Hello guys, I need your help :)

I run my mezzanine project on gunicorn and nginx (is serving static files).
I have problem with tinymce,
for Insert/Edit Image, Insert/Edit Embedded Image,and so on I am getting 404 Not found nginx/1.1.19.

My nginx.conf

  location /media {
  root   /home/user/sites/mysite/static/;
}

  location /static {
  root   /home/user/sites/mysite/;
    }


Reply all
Reply to author
Forward
0 new messages