Previously we discussed how to implement a simple version of Github Pages using Nginx. This time we will discuss how to deploy multiple sites under one IP address.

Talk about your needs first: It’s no secret that accessing foreign websites in China can be slow or cumbersome. It can be very difficult for programmers to view documents when using the framework, but some third-party library documents can be downloaded locally. For example, Qt comes with a document browsing tool called Qt Assistant, which makes it much faster to view documents on the software than online documents.

Qt assistant screenshots

Screenshot of qt online documentation

Some third-party libraries, such as Eigen OpenMesh, do not provide such convenient tools and provide documents in HTML format. There are tutorial blogs, e-books, and static web pages in the form of mkDoc Jekyll Hexo. Most of them have these characteristics:

  1. Access to online documents and e-books from China is extremely slow;
  2. Offline documents such as HTML and Markdown are provided, and it is easy to obtain offline documents.

In order to get a smooth experience like online documents, I decided to deploy some documents and e-books on my raspberry PI, so that WHEN I read documents on the campus network, I can have a good experience, and will not be affected by computer shutdown, restart and so on. I can even share accelerated documents with my classmates.

Deployment plan

Here I use two offline HTML documents (eigen, OpenMesh) and a mkDoc tutorial (Learnopengl-CN) to demonstrate

Plan a

I can differentiate different documents in the form of a website directory hierarchy, with the following effect:

  • pi.mcoder.cc/eigen/Documents representing eigen;
  • pi.mcoder.cc/openmesh/A document representing OpenMesh;
  • pi.mcoder.cc/learnOpenGL/The learningOpenGL tutorial url

Scheme 2

Using different secondary domain names to distinguish different documents, the effect is as follows:

  • eigen.mcoder.ccDocuments representing eigen;
  • openmesh.mcoder.ccA document representing OpenMesh;
  • learnopengl.mcoder.ccLearningOpenGL tutorial url

The two approaches have their own characteristics. The first approach emphasizes different pages on the same site, while the second gives a sense of isolation on the site.

Implementation scheme

To prepare the document

Eigen and OpenMesh documents are generated using doxyGen tools, and the environment needs to be configured first.

sudo apt install nginx doxygen
Copy the code

Cmake generates the Makefile. Make doc generates the document.

Get the source code from Gitee's accelerator repository
git clone https://gitee.com/mirrors/eigen-git-mirrorsource.git
cd eigen-git-mirrorsource
mkdir build && cd build
cmake ..

# Compile to generate documentation
make doc

Copy the generated document to the specified path
sudo cp -r doc/html /var/www/html

Change the name of the eigen document
sudo mv /var/www/html/html /var/www/html/eigen-doc
sudo chmod a+wr  var/www/html/eigen-doc
Copy the code

After compiling, the document was located in Build /doc/ HTML. We copied the document to an easy to remember path. We chose nignx’s default path /var/www/html/ to give nignx’s process enough permission to read the file.

In the same way, openMesh can be configured in /var/www/html/openmesh-doc

The same is not true for Learnopengl-CN, which requires a service to access

Install the content of mkdocs
sudo pip3 install mkdocs pyton-markdown-math

# clone warehouse
git clone https://github.com/LearnOpenGL-CN/LearnOpenGL-CN.git
cd LearnOpenGL-CN

# Start web serviceMkdocs serve - a 0.0.0.0:8000Copy the code

Hierarchical by directory

With directory hierarchy, we assume that a DNS resolution can be configured for raspberry PI, either through domain name resolution or using the hosts file of the modified client. In the experiment, we add the following records to the /etc/hosts file:

10.4.54.76 pi.mcoder.cc eigen.mcoder.cc openmesh.mcoder.cc learningopengl.mcoder.cc
Copy the code

Conf file in /etc/nginx/conf.d and write the following content to implement this solution deployment.

server {
    # Bind port
    listen 80;
    listen[: :] :80;

    Configure the server name
    server_name pi.mcoder.cc 10.4.54.76;

    root /var/www/html;

    # eigen document
    location /eigen {
        alias /var/www/html/eigen_doc;
        index index.html index.htm;
        try_files $uri $uri/ =404;
    }

    # Learning OpengL documentation
    location /learnOpenGL/ {
        proxy_pass_header Server;
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Scheme $scheme;
        proxy_pass http://127.0.0.1:8000/;
        index index.html index.htm index.jsp;
    }

    # openMesh document
    location /openmesh {
        alias /var/www/html/openmesh_doc;
        index index.html index.htm;
        try_files $uri $uri/ =404; }}Copy the code

Modify the configuration and restart the web server.

Check the configuration file for errors
sudo nignx -t

Restart the web server
sudo systemctl restart nginx
Copy the code

At this point, we can access different blogs through different layers of the web page.

Differentiate blogs by using secondary domain names

In this way, we could write a file, a domain name can also write configuration of multiple documents in the same document, all is ok, here is convenient for the purpose of writing in the same file/etc/nginx/conf. D/doc2. Conf.

server {
    listen 80;
    listen[: :] :80;

    server_name eigen.mcoder.cc;
    root /var/www/html/eigen_doc;
    index index.html index.htm;

    location / {
        try_files $uri $uri/ =404; }}server {
    listen 80;
    listen[: :] :80;
    server_name openmesh.mcoder.cc;

    root /var/www/html/openmesh_doc;
    index index.html index.htm;

    location / {
        try_files $uri $uri/ =404; }}server {
    listen 80;
    listen[: :] :80;
    server_name learningopengl.mcoder.cc;

    root /var/www/html;
    index index.html index.htm;

    location / {
        proxy_pass_header Server;
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Scheme $scheme;
        proxy_passhttp://127.0.0.1:8000/; }}Copy the code
Check the configuration file for errors
sudo nignx -t

Restart the web server
sudo systemctl restart nginx
Copy the code

conclusion

By doing so, we have implemented two ways to host multiple documents on a raspberry PI, either through multiple hierarchies under the same domain name or through different domains. It would be a great pleasure to mount the images of frequently used documents under the campus network for lab students to use together.

Reference

  1. How to implement a simple version of Github Pages using Nginx
  2. Eigen online documentation
  3. Openmesh online document
  4. learningOpengl-cn