I am trying to setup a reverse proxy in nginx to serve static contents. I am having issue in correctly setting up; below is my nginx config:

server {
    listen       80;
    server_name  mysub.domain.com;
    access_log off;

   resolver valid=5s;
   set $backend "www.originaldomain.com";
   location / {

      proxy_cache my_cache;
      proxy_pass https://$backend;

If I try a resource of originaldomain over mysub.domain.com .. it wouldn't work.. and if I see error log, it seems the nginx is requesting the resource to originaldomain's IP like below;

2018/06/09 17:47:13 [crit] 9825#0: *111 mkdir() "/store/cache/1" failed (13: Permission denied) while reading upstream, client:, server: mysub.domain.com, request: "GET /path/to/image.png HTTP/1.1", upstream: "", host: "mysub.domain.com"

and when looking up image.png over IP, it cannot be found, to download resource correctly it needs to be looked up through domain name instead of its IP.

Any ideas?

Thanks in advance.

  • please provide complete version of your nginx configuration
    – Reza
    Jun 9, 2018 at 18:37

1 Answer 1


nginx can only connect to IP addresses, that's how TCP/IP works.

In the location / stanza you need to add a line

proxy_set_header Host $backend;

to pass that header line to the backend.

I'd also investigate that mkdir() "/store/cache/1" failed (13: Permission denied) error. Either configure another location for the cache files or create /store/cache with suitable permissions for the ID nginx is running as.

  • Thanks for clarification, it was more about fixing the permission error. Thanks again for help.
    – Alyas
    Jun 11, 2018 at 12:40
  • Just to add it... I had SELinux enforcing mode, change to permissive/disabled fixed the problems :)
    – Alyas
    Jun 11, 2018 at 16:18
  • But you should not ignore the proxy header comment, as multiple vhost on remote server (if any) will require the header to be set.
    – vmx
    Apr 22, 2019 at 10:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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