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.

I am trying to set up Nginx in front of Apache as a reverse proxy and to serve static files. I 301 http to https, and provide the directives in https section to serve a static folder via an alias. However, for some strange reason the files get served via http.

Here's my Nginx site config:

    server {
            listen   80; 
            listen   [::]:80;
            access_log off;
            server_name site.com www.site.com;
            return 301 https://$server_name$request_uri;

        }

    server {
            listen   443;
            ssl on;

            ssl_certificate /usr/local/sslcert/my.crt;
            ssl_certificate_key /usr/local/sslcert/my.key;

            access_log off;
            server_name site.com www.site.com;


            location /public/ {
            alias /var/www/public/;
            expires max;
            add_header Pragma public;
            add_header Cache-Control "public";
            }


            location / {

            root /var/www/;
            index index.php

            client_max_body_size    10m;
            client_body_buffer_size 128k;

            proxy_send_timeout   90;
            proxy_read_timeout   90;
            proxy_buffer_size    128k;
            proxy_buffers     4 256k;
            proxy_busy_buffers_size 256k;
            proxy_temp_file_write_size 256k;
            proxy_connect_timeout 30s;

            proxy_redirect  off;

            proxy_pass   http://127.0.0.1:3333/;

            proxy_set_header   Host   $host;
            proxy_set_header   X-Real-IP  $remote_addr;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
            }



            location /push {
            root /var/www/;
            rewrite /push(.*) /$1 break;
            proxy_pass https://127.0.0.1:8332/push/;
            proxy_redirect off;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            }

             location ~ /\.ht {
                    deny all;
            }
    }

What am I missing?

share|improve this question
1  
site.com just redirected me to salesforce.com. What is going on here? Isn't that your site? –  Michael Hampton Jul 28 at 21:12
    
no, I have changed it for privacy purposes –  user3521621 Jul 28 at 22:27
2  
You may need to provide the actual name in order for anyone to figure this out. –  Michael Hampton Jul 28 at 23:05

2 Answers 2

This might not be the actual reason for the problem, but it causes difficulties anyway.

You are using root inside location blocks, which doesn't work out nicely in general.

Try this configuration:

server {
        listen   80; 
        listen   [::]:80;
        access_log off;
        server_name site.com www.site.com;
        return 301 https://$server_name$request_uri;
}

server {
        listen 443 ssl;
        listen [::]:443 ssl;

        ssl_certificate /usr/local/sslcert/my.crt;
        ssl_certificate_key /usr/local/sslcert/my.key;

        access_log off;
        server_name site.com www.site.com;

        root /var/www;

        location /public/ {
            expires max;
            add_header Pragma public;
            add_header Cache-Control "public";
        }

        location / {
            index index.php

            client_max_body_size    10m;
            client_body_buffer_size 128k;

            proxy_send_timeout   90;
            proxy_read_timeout   90;
            proxy_buffer_size    128k;
            proxy_buffers     4 256k;
            proxy_busy_buffers_size 256k;
            proxy_temp_file_write_size 256k;
            proxy_connect_timeout 30s;

            proxy_redirect  off;

            proxy_pass   http://127.0.0.1:3333/;

            proxy_set_header   Host   $host;
            proxy_set_header   X-Real-IP  $remote_addr;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        }

        location /push {
            rewrite ^/push(.*) /$1 break;
            proxy_pass https://127.0.0.1:8332/push/;
            proxy_redirect off;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

         location ~ /\.ht {
                deny all;
        }
}

Changes:

  • Moved ssl definition to the listen line
  • Added IPv6 to SSL section
  • Moved root directive to server level
  • Removed unneeded alias and root definitions from location blocks, the server level root directive covers these
  • Added start of line ^ to the push rewrite rule.
share|improve this answer
    
thanks for the feedback! unfortunately that does not solve the issue :( –  user3521621 Jul 30 at 18:19
up vote -1 down vote accepted

So the issue was actually with Zend Framework BaseUrl setting. I have removed it, and everything is working now.

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.