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

Added support for multiple domains for Apache config in portal generator #3264

Merged
merged 1 commit into from Jan 2, 2024

Conversation

abujeda
Copy link
Contributor

@abujeda abujeda commented Dec 21, 2023

Added support to remove the automatic redirect to the servername/proxy_server domains without having to remove the servername property or disabling rewrites.

We would like to access the OnDemand instance through multiple domains, but want to keep the rewrite rules and the servername config in place and use server_aliases for the alternative domains.

I was thinking of adding a check based on server_aliases being empty, but then I realized that this change will affect existing configurations. That is why the new property multiple_hosts was added.

Comment on lines 89 to 93
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(<%= @proxy_server %>(:<%= @port %>)?)?$ [NC]
RewriteRule ^(.*) <%= @ssl ? "https" : "http" %>://<%= @proxy_server %>:<%= @port %>$1 [R=301,NE,L]
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not add more RewriteConds for all server aliases?

Something that ends up being like this:

RewriteCond %{HTTP_HOST} ^olddomain.com [NC]
RewriteCond %{HTTP_HOST} ^www.olddomain.com [NC]
RewriteCond %{HTTP_HOST} ^newdomain.com [NC]

Copy link
Contributor

Choose a reason for hiding this comment

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

Though I do wonder how you get into this spot or why we have this redirect at all.

@treydock do we need this redirect? If you have multiple vhosts in apache - you wouldn't hit this block at all right? (you'd hit the other directives in the other vhost).

I guess I'm wondering under what conditions you'd actually want this to happen. If you're trying to use a different %{HTTP_HOST} why would apache be routing you to this vhost?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not an Apache expert, but local after testing with the ood-portal.conf Apache config with a single VirtualHost directive, all domains that point to the server IP are served by the same VirtualHost, ignoring the ServerName and ServerAlias.

I guess as it is the only VirtualHost config it becomes the default.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you prefer, I can update to use the @server_aliases as you mentioned in the previous comment. Initially I thought that adding the aliases might change how it currently works, but because of the redirect taking precedence, I don't think it does.

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess as it is the only VirtualHost config it becomes the default.

This is correct. A single VirtualHost will serve all traffic pointed at Apache.

@treydock do we need this redirect? If you have multiple vhosts in apache - you wouldn't hit this block at all right? (you'd hit the other directives in the other vhost).

The purpose with these rewrites was so that if you have this single VirtualHost, and go to like ood-foo.example.com but the ServerName is ood.example.com the rewrite would ensure all web addresses end up being the ServerName.

You'd still hit this ReWrite if ood-portal is the first VirtualHost loaded and the traffic doesn't match any of the other VirtualHosts. In Apache the order of configs is really important so if you had like z-example.conf that had ServerName foo.example.com and the ood-portal.conf was ServerName ood.example.com then any address pointed at this server that didn't match foo.example.com or ood.example.com would end up being rewritten as ood.example.com and served by OnDemand.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK so we do need it, or should keep it.

Wouldn't something like this have the same behavior? (I'm just trying to avoid more and more and more configs)

<%- (@server_aliases + [@proxy_server]).each do |server| -%>
RewriteCond %{HTTP_HOST} !^(<%= server %>(:<%= @port %>)?)?$ [NC]
<%- end -%>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This solution works for our use case. I have updated the PR with your suggestion.

Copy link
Contributor

@johrstrom johrstrom left a comment

Choose a reason for hiding this comment

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

Thanks!

@johrstrom johrstrom merged commit 20283d3 into OSC:master Jan 2, 2024
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants