1

Alright guys, I recently started messing with nginx and I need some help. I spent an entire day trying to figure this and I am simply done with it.

After I set the header in php for x-accel-redirect to work, I get an empty response. I am trying to serve image files from an external location to the website's root folder but in the same computer.

Can somebody point out what I'm doing wrong?

The funny/weird part is that I do not get any errors or warnings from nginx. I also do not get anything on the access/error logs, even with debug error logs turned on.

here is my nginx.conf

    user Omi Admin;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  debug;
#error_log  /usr/local/var/log/nginx/error.log  debug;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       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"';

#access_log  logs/access.log  main;

sendfile        on;
#tcp_nopush     on;

#keepalive_timeout  0;
keepalive_timeout  65;

#gzip  on;

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;

location /unprocessed {
internal;
alias /usr/local/MyMateApp/ean_images/unprocessed;  
    }

root /Users/Omi/Desktop/CustomerServiceWebsite/www;
index index.html index.htm index.php;

    error_page  404              /404.html;        

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        try_files      $uri = 404;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
#    listen       8000;
#    listen       somename:8080;
#    server_name  somename  alias  another.alias;

#    location / {
#        root   html;
#        index  index.html index.htm;
#    }
#}


# HTTPS server
#
#server {
#    listen       443 ssl;
#    server_name  localhost;

#    ssl_certificate      cert.pem;
#    ssl_certificate_key  cert.key;

#    ssl_session_cache    shared:SSL:1m;
#    ssl_session_timeout  5m;

#    ssl_ciphers  HIGH:!aNULL:!MD5;
#    ssl_prefer_server_ciphers  on;

#    location / {
#        root   html;
#        index  index.html index.htm;
#    }
#}
include servers/*;

}

And here is where I set the header in php

header('X-Accel-Redirect: /unprocessed/' . $fileName);

I get a response back but it's simply empty.

Miguel
  • 772
  • 1
  • 7
  • 24
  • Is it correct that `unprocessed` appears in the pathname twice? Or should the `root` be `/usr/local/MyMateApp/ean_images` instead? – Richard Smith May 24 '18 at 10:32
  • it shouldn't be twice....but the path does contain the 'unprocessed' folder. for example '/usr/local/MyMateApp/ean_images/unprocessed/123.png' is an image file. – Miguel May 24 '18 at 10:34
  • `nginx` will concatenate the `root` value with the URI value. Your rewritten URI already contains `/unprocessed/` in it - so the `root` should not. See [this link](http://nginx.org/en/docs/http/ngx_http_core_module.html#root). – Richard Smith May 24 '18 at 10:38
  • Alright @RichardSmith, I changed it to alias as it is more appropriate....it still doesn't work.... – Miguel May 24 '18 at 10:42
  • I figured out what the problem is (was). I was using phpstorm when developing this application and it was proxying the call. Once I tried accessing the server directly everything worked like a charm. – Miguel May 25 '18 at 01:08

0 Answers0