Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

as title says i'm trying to serve my static content form another domain hosted on the same server using nginx.

This is my server config:

  server {
    listen 80;
    server_name static-sexparken.nu;
    rewrite ^ http://static-sexparken.nu$uri permanent;
  }

  # the server directive is nginx's virtual host directive.
  server {
    # port to listen on. Can also be set to an IP:PORT
    listen 80;

    # Set the charset
    charset utf-8;

    # Set the max size for file uploads to 10Mb
    client_max_body_size 50M;

    # sets the domain[s] that this vhost server requests for
    server_name static-sexparken.nu; 

    # doc root
    root /var/www/static-sexparken.nu/public;

    # vhost specific access log
    #access_log  /var/log/nginx_access.log  main;


    # Set image format types to expire in a very long time
    location ~* ^.+\.(jpg|jpeg|gif|png|ico)$ {
        access_log off;
        expires max;
    }

    # Set css and js to expire in a very long time
    location ~* ^.+\.(css|js)$ {
        access_log off;
        expires max;
    }

    # Catchall for everything else
    location / {
      root /var/www/sexparken.nu/public;
      access_log off;

      index index.html index.shtml;
      expires 1d;

      #try_files $uri $uri/404.html;

      if (-f $request_filename) {
        break;
      }
    }

    location ~* ^/(pkg|rpms)/ {
      autoindex on;
    }

    error_page 500 502 503 504 /500.html;
    error_page 404 /404.html;

  }

What happens when i try to access an image on the domain direcly, i get:

This problem can sometimes occur if you are disabled or refusing to accept cookies.

from firefox as an error. And these are ofcourse linked correctly from the website aswell, and i get nothing.

What might be the problem here? any help appreciated.

share|improve this question

1 Answer 1

You should be getting a duplicate server name warning when you start nginx. Both of your server blocks are matching the same hostname, and the first one is used, because, well, it's first. You're telling it to redirect to the same hostname, so it loops forever. Perhaps you meant to add a www. to that first server_name?

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.