How to change the host IP sent in emails to new Gi

2019-06-08 03:37发布

问题:

I have set up a Bitnami GitLab stack as a running virtual machine instance using VMWare Workstation on my personal dedicated Windows server (host) running out of my home office. My dedicated Windows server host has a publicly visible static IP address.

I have successfully gained public access to the GitLab application running as guest by setting up port forwarding within VMWare Workstation's Virtual Network Editor (using NAT translation, not bridging). I am able to access the GitLab web interface from any internet-connected computer just by typing the static IP (including my chosen port).

I have also successfully set up two Git repositories in the running GitLab instance.

Sending email needs to be enabled, requiring a modification of a settings file, and this worked straightforwardly (here is a link that explains how to set up SMTP properly).

Before inviting new users, I wanted to test the functionality by inviting myself first (using a secondary email address).

When inviting a user, an invitation/confirmation email is sent to that user that provides a link to login to the GitLab instance. However, I find that the URL provided in the invitation email is the local network IP address (i.e., 192.168.44.129) rather than the publicly visible static IP address.

I do not see any settings in the GitLab web interface itself to change the host IP included with email invitations, so I assume I need to change a setting in a configuration file somewhere. But I have no idea if this should be a GitLab setting, an Nginx setting, a RoR setting, or some other setting; and what the setting / setting file is.

The best links I can find about this (here, here, and here) do not seem to lead me to sufficient clarity to take an efficient guess as to what to do.

How do I change the URL (host IP) that is provided in invitation emails to new users via GitLab from the local network IP address to a globally-visible (static) IP address?

回答1:

Two hints pointed the way for me, and once I did resolve the issue (as I am about to describe), I found the details laid out in the deceptively named subsection of the Bitnami GitLab stack official documentation.

The first hint was to be found in a not-very-highly-upvoted answer here (in comparison with other answers and the accepted answer, some of which had many more upvotes). The setting for the host IP and port used in the GitLab account invitation emails is to be found in the gitlab.yml file (as of today, the full path of this file on the VM stack (and probably other) installations is /opt/bitnami/apps/gitlab/htdocs/config/gitlab.yml; see the host and port settings, as well as other overall useful settings). (I'm not experienced with the Rails universe, and using the .yml settings file is a touch, apparently, of the way Rails apps in general do things, if I understand correctly.)

The above step does succeed - but only until the server is restarted. Unfortunately, when the server is restarted, the host setting is overwritten with whatever is present in ifconfig as the IP address (the port entry remains the same as whatever you enter).

The second hint was how to resolve this problem; I found it here. There is a special script in the init.d folder whose specific purpose is just to reset the host parameter in this (and perhaps other?) .yml settings files. (What a wonderful "convenience" in my scenario.) Simply commenting out the single line exec /opt/bitnami/apps/gitlab/bnconfig --machine_hostname ... in this file (by adding a # at the front of the line) resolved the problem.

Once both of the above changes were made, the problem was resolved. GitLab invitation emails successfully include the desired static IP address (and port) of the server, even through server restarts.

As I mentioned above, once I resolved the problem, I then found that the answer to this question was already laid out in the official Bitnami GitLab documentation (note: both hint #1 and hint #2, from above, are tucked away in this same subsection of the documentation - one after the other - they're not prominent; they don't stand out very well; they come across as secondary details upon first reading, I think; the formatting does not draw attention to the file name and path, which would be helpful, I think; and the subsection name in which they are present does not particularly make it clear that this would be the correct subsection to look at, except in retrospect, in my opinion).


ADDENDUM: For anyone who finds it useful, there's an added detail required to get email working from your own personal server with GitLab - I made only a brief passing mention of this in the question, because I had already done it.

But for completeness for future visitors, I should mention that you need to set up SMTP properly on your GitLab instance by making a modification to a file named production.rb (the full path as of today is /opt/bitnami/apps/gitlab/htdocs/config/environments/production.rb). Specifically, as is also to be found in the official Bitnami GitLab documentation, you must add a config.action_mailer.smtp_settings {...} block and add/uncomment a few other settings in order to be able to send emails from your running GitLab instance.