Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds root directive to vhost_header and vhost_ssl_header templates. #143

Closed
wants to merge 2 commits into from

Conversation

bradfier
Copy link

This change will result in there being a 'root' directive in both the
server block, and the location sub-block. This is a perfectly valid
configuration and avoids the possible issue of having a location
with no 'root' if it isn't explicitly set.


From #142, I thought this was the most concise way to solve the 'no root' issue, another possibility would be to remove the root directive from the default '/' location, but having the duplicate has no ill-effects and keeps the '/' location consistent with any others added to the vhost.

I don't like schkovich's solution (d22a259) as it removes the ability to define locations blocks with different document roots.

@@ -26,6 +26,10 @@ server {
}
<% end -%>

<% if defined? @www_root -%>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if @www_root should be more than sufficient here, since it is undef by default. https://github.com/jfryman/puppet-nginx/blob/master/manifests/resource/vhost.pp#L121

Also, <%-?

@jfryman
Copy link
Contributor

jfryman commented Oct 3, 2013

Dig it! Can you clean it up a bit? I'll get it merged in.

@bradfier
Copy link
Author

bradfier commented Oct 3, 2013

Tidied up the two new blocks, stripped an extra newline so I can leave it without <%-, which keeps it consistent with the rest of the blocks in the template, and removed the pointless defined?.

@@ -25,6 +25,9 @@ server {
return 301 https://$host$request_uri;
}
<% end -%>
<% @www_root -%>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be if @wwwroot?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that @www_root is right, but there absolutely needs to be an if here. Thanks for double-checking!

https://github.com/jfryman/puppet-nginx/blob/master/manifests/resource/vhost.pp#L123

@bradfirj: can you make this change really quickly? I'll get it merged in. 🍻

@bradfier
Copy link
Author

Thanks @3flex, chucked the missing ''if'' in.

@3flex
Copy link
Contributor

3flex commented Nov 25, 2013

Also now there are tests, do you think you could add these conditions to spec/defines/resource_vhost_spec.rb? You should be able to base them on the test for the non-SSL version (see https://github.com/jfryman/puppet-nginx/blob/master/spec/defines/resource_vhost_spec.rb#L138)

@schkovich
Copy link

@bradfirj Unfortunately having root defined inside location block does have significant side effects:

[error] 2943#0: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream

Please check http://linux.ioerror.us/2013/05/cant-get-php-fpm-with-nginx-to-work/

P. S. Sorry about the late reply. :) I missed your comment somehow. :(

@bradfier
Copy link
Author

@schkovich The example you linked gives an error not because the questioner has defined a root inside a location but because they have defined it wrongly!

Consider, from the linked article/question:

location ~ .php$ {
    root           html;
    ....
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
}

The issue here is not that root has been defined inside location ~ .php$ but that it has been defined as 'html'.

Thus the SCRIPT_FILENAME passed to FastCGI will be html$scriptname, as opposed to /home/webuser1/www/public$scriptname, which is the behaviour I suspect the author was looking for.

All that said, there are a limited number of circumstances where you would want to define root inside a location block instead of using alias, however I thought it would be useful to allow the sysadmin to make their own decision on that matter.

@schkovich
Copy link

@bradfirj I am sorry I did not check the question at all but only the answer. Anyway get https://github.com/schkovich/ultramarin spin up Virtualbox and you will get the error.

Further on, I truly do not understand why an option to do something that is clearly wrong should be provided. IMHO it is way more better to prevent sysadmins from doing stupidity.

@jfryman
Copy link
Contributor

jfryman commented Feb 25, 2014

@bradfirj I'm going to second the need for tests here. Also, needs another rebase. :)

@schkovich You bring up an interesting point. As far as the ability to do something wrong ... I'd rather provide sane defaults and let a user make silly decisions on their own. For the most part, our target audience is going to be sysadmins or other administrators. Those wanting to go far off the beaten path should absolutely be able to.

This change will result in there being a 'root' directive in both the
server block, and the location sub-block. This is a perfectly valid
configuration and avoids the possible issue of having a location
with no 'root' if it isn't explicitly set.
Drops the explicit ''defined?'' check as suggested by jfryman, and clears some pointless whitespace.
@jfryman
Copy link
Contributor

jfryman commented Jun 24, 2014

Way old. Thanks for taking a pass at this... going to revisit when 🕐 allows. Please reopen and rebase if you wanna take another pass at this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants