Thursday, December 12, 2019

Gitlab - Stop Showing your gitlab setup and repositories in google search results


If your gitlab setup is accessible by global url but you do not want to show results in Google, here is solution for you.

1. You can make your gitlab url restricted to limited IPs only. Gitlab works on default port 89. You must have used a web server to serve the gitlab url globally. Your web server may be apache, nginx or some other web server. You can add  attributes in your virtualhost which will stop accessing gitlab from undefined IPs.

2a. Sometimes you need to access gitlab from undefined IPs and it is not feasible to change the Virtualhost setting every time. If you can not restrict your gitlab setup to some IPS but still you do not want to be in Google search results, you can try this solution.
Always make your repository and group private. Do not make any public repository or any public group. Public repositories and public groups are visible in google search results. Gitlab has settings in admin area. After enabling it, no registered user can create a public repository/group. Only admin will have access to create public repository and group.
Here is the settings.

Admin Area > Settings > General > Visibility and access controls > Restricted visibility levels

Check the box Public.
Now no registered user can create a Public repository and Group.

2b. After following solution 2a, you need to implement solution 2b. Like every other web application, gitlab too has robots.txt file.

robots.txt is a direction for search engines and crawlers. They follow it blindly. If you write a rule to not allowing your site in search result, your web application will not be listed.

By default gitlab allows to show login page and explore page to list in search results. Explore page contains list of all public repositories and groups and if your gitlab has some of them, it will be listed in search results. You need to modify your gitlab robots.txt. Here is the path.

/opt/gitlab/embedded/service/gitlab-rails/public/robots.txt

Now comment every single line except these two

 User-Agent: *
 Disallow: /

it will restrict to show your gitlab url in search results. If it is already listed, once you make changes in robots.txt, it will be gone after some days.

Wordpress - https mixed content issue

After configuration of ssl in your wordpress site, the most annoying problem is mixed content error. Your browser shows error "Your connection is not fully secure". Here is the solution for you to fix the issue.

Solution : 1
1. You need to change all urls in code from http to https manually. If there are any js files in any plugin or fusion directory of Uploads, you need to find those and replace them.
2. You can install Go Live plugin in your wordpress site to replace all urls in database. It provides easy option to replace all urls with http into https.

OR

Solution : 2
There is one easy solution, you can install a wordpress plugin name "Really Simple ssl". Once you activate it, it delivers all the urls in browser with https and you do not get same error again.
Let me know which solution worked for you.

Monday, November 11, 2019

Run php 7 project in docker container where php 5.6 project is running on Host

Run multiple php versions in docker and host with apache / Run multiple websites on php 7 docker without affecting php 5.6 of host.

If one of your php project is running on php 5.6 of ubuntu/centos/fedora, Now if you want to run another project with php 7 inside docker container. It is quite good idea to run multiple php projects on same machine.

1) Suppose you have container where apache2 and php 7 is running

2) You have already launched this container with mapped port and htdocs path.
docker run -it -v /var/www/html:/var/www/html -p 7030:80 ubuntu:16.04 /bin/bash
As our 80 port of host is already busy, php 5.6 project is running there so we mapped 80 port of docker with 7030 port of host.
We have also mounted /var/www/html of host in /var/www/html of docker. We do not need to go inside docker container to access project files, it can be accessed in html folder of host as we already mapped host and docker directory.

3) Point your subdomain to the public IP of host and add a virtualhost in apache config of host.
<VirtualHost *:80>
ServerName php7.project.com
ProxyPreserveHost On
ProxyRequests off
ProxyPass / http://127.0.0.1:7030/
ProxyPassReverse / http://127.0.0.1:7030/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
We have proxy passed to port 7030 as 80 port of docker apache is mapped with 7030 port of host.
'ProxyPreserveHost On' parameter, does not show proxy-passed ip for js and css. It keeps the servername on every page.

5) Now create a file php7project.conf in /etc/apache2/sites-available of docker-apache with following content
<VirtualHost *:80>
ServerName php7.project.com
DocumentRoot /var/www/html/projectfoldername
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

6) Enable the site.
cd /etc/apache2/sites-available
a2ensite php7project.conf

7) Now virtualhostof host apache is mapped with virtualhost of docker apache and it will open the site.
http://php7.project.com/

8) Once you make the correct database connection in your docker apache project, your site is ready to access.