1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
 
    # reserve 1MB under the name 'proxied' to track listing uploads
    upload_progress proxied 1m;

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

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;



    #####################################################################################################################
    # Porelo Server
    #####################################################################################################################
    upstream unicorn{
      server unix:/Users/kirkquesnelle/sites/porelo/tmp/sockets/unicorn.sock fail_timeout=0;
    }

    server {
      listen       80 default;
      server_name  localhost;
      root /Users/kirkquesnelle/Sites/porelo/public;
      client_max_body_size 100m;
      
      autoindex on;

      try_files $uri/index.html $uri @unicorn;
  
      #####################################################################################################################
      # Fast file upload for listing photos
      #####################################################################################################################
      # Upload form should be submitted to this location
      location /upload {
        

        # Specifies upload rate limit in bytes per second. Zero means rate is unlimited.
        upload_limit_rate 8k;

        proxy_pass http://127.0.0.1;
        
        # Pass altered request body to this location
        upload_pass   @unicorn;

        #rewrite ^/upload/(.*)$ /$1 break;
        #proxy_pass http://unicorn;

        # Store files to this directory
        # The directory is hashed, subdirectories 0 1 2 3 4 5 6 7 8 9 should exist
        upload_store /Users/kirkquesnelle/Sites/porelo/tmp/uploads 1;

        # Allow uploaded files to be read only by user
        upload_store_access user:r;

        # Set specified fields in request body
        upload_set_form_field $upload_field_name.name "$upload_file_name";
        upload_set_form_field $upload_field_name.content_type "$upload_content_type";
        upload_set_form_field $upload_field_name.path "$upload_tmp_path";

        # Inform backend about hash and size of a file
        upload_aggregate_form_field "$upload_field_name.md5" "$upload_file_md5";
        upload_aggregate_form_field "$upload_field_name.size" "$upload_file_size";

        upload_pass_form_field "^X-Progress-ID|^authenticity_token|^submit$|^description$";


        upload_cleanup 400 404 499 500-505;

        
        track_uploads proxied 30s;
      }

      #####################################################################################################################
      # Upload Progress 
      #####################################################################################################################
      location ^~ /progress {
        # report uploads tracked in the 'proxied' zone
        upload_progress_json_output;
        report_uploads proxied;
      }
      

      #####################################################################################################################
      # Unicorn Proxy Endpoint      
      #####################################################################################################################
      location @unicorn{
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_pass http://unicorn; 
      }

      # redirect server error pages to the static page /50x.html
      #
      error_page   500 502 503 504  /50x.html;
      keepalive_timeout 5;

    }

}