0

I want to perform a 301 redirect on port 80 to https 443

The config currently looks like this:

server {
    listen      78.34.163.12:80;
    server_name example.com *.example.com;

    return 301 https://$host$request_uri;

    location / {
        proxy_pass      http://78.34.163.12:8085;
        location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|tif|tiff|css|js|htm|html|ttf|otf|webp|woff|txt|csv|rtf|doc|docx|xls|xlsx|ppt|pptx|odf|odp|ods|odt|pdf|psd|ai|eot|eps|ps|zip|tar|tgz|gz|rar|bz2|7z|aac|m4a|mp3|mp4|ogg|wav|wma|3gp|avi|flv|m4v|mkv|mov|mpeg|mpg|wmv|exe|iso|dmg|swf)$ {
            root           /home/dave/web/gldn.page/public_html;
            access_log     /var/log/apache2/domains/example.com.log combined;
            access_log     /var/log/apache2/domains/example.com.bytes bytes;
            expires        max;
            try_files      $uri @fallback;
        }
    }

    location /error/ {
        alias   /home/dave/web/example.com/document_errors/;
    }

    location @fallback {
        proxy_pass      http://78.34.163.12:8085;
    }

    location ~ /\.(?!well-known\/|file) {
       deny all;
       return 404;
    }

    include /home/dave/conf/web/example.com/nginx.conf_*; 
}

So, my question is:

After that line return 301 https://$host$request_uri;

does anything else get processed?

eg:

are any file stored in the cache?

will any errors get logged?

If not, is it not better to simply have:

server {
    listen      78.34.163.12:80;
    server_name example.com *.example.com;

    return 301 https://$host$request_uri;
}

Hope you can help me understand this :)

Thanks

3
  • It isn't necessarily the order of the statements that's important. But all of the location statements will be ignored when there is a return statement anywhere in the server context. Jun 23 at 10:48
  • So, in this case, I can use my much shortened version? Making it more obvious what is to happen?
    – Dave
    Jun 23 at 10:56
  • You will need to determine the purpose of the include /home/dave/conf/web/example.com/nginx.conf_*; statement, but you are essentially correct. Jun 23 at 11:53

0

Your Answer

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

Browse other questions tagged or ask your own question.