Contents
Preface
For building a website in a home data center, having your own image storage is a must: first, saving money is the bottom line, and you would never spend money to borrow someone else's help if you can build it yourself; second, in the future, you will need to refine the regional processing of image storage access (return different image storage cache addresses according to the source addresses of access from China and abroad), and you will also need your own image storage (I will explain this in detail in another article later, and it requires the dynamic redirection of cloudflare). For the construction of the image storage, I chose the docker version of chevereto to implement it.
In fact, almost all applications can be deployed through source code, but I will give priority to deploying applications as long as there is a docker version. After all, I have a dedicated docker deployment environment, which is convenient for deployment and migration. The source code deployment method is only an alternative method that I will use when docker deployment is inconvenient or there is no docker version at all, such as deploying V visa-free (see my other article:Linux panel series: Deploy V-sign-free in source code based on Baota panel).
deploy
Initialize the database
If you use docker-compose to deploy, there is no such step, because the database has been initialized in the corresponding docker-compose.yml file. If you use docker run to deploy, you will be asked to enter the relevant information of the database when you log in to chevereto for the first time, including host name, database name, username and password, etc. Therefore, if you use docker run, you need to have an existing mariaDB (or mysql) database (or create a new one) and initialize it yourself. For detailed initialization steps, please refer to my other article:Tips and tricks: Create a new empty database and grant permissions to corresponding users.
If there is no existing database, you need to create a new database container and then initialize the database. Refer to the following command:
docker run --name=mariadb -d --restart=always \ -p 3306:3306 \ #Map the host port to port 80 inside the container. Please modify it according to your actual situation -v /docker/mariadb/db:/var/lib/mysql \ #Map the specified folder of the host to the /var/lib/mysql directory inside the container -e MARIADB_ROOT_PASSWORD=yourpassword \ #Specify the root user password mariadb:10.11
Note: Please delete the comment after #
Assume that after initialization, the data information is as follows (all of these need to be filled in according to your actual configuration):
Database host : 192.168.10.130 (IP address of the host machine where the mariaDB container is located. If it is deployed locally, it is 127.0.0.1. If no port is specified, the default port is 3306. If it is not 3306, use :port to specify the actual port mapped on the host machine)
Database name: chevereto (chevereto library name)
Database user: chevereto (the user name of the user with full operation permissions corresponding to the chevereto database)
Database user: chevereto (the password of the user with full operation permissions corresponding to the chevereto database)
Database table prefix: chv_ (If the same chevereto library is used by multiple chevereto containers at the same time, a prefix is needed to distinguish the tables used by different containers)
Create a folder on the host that needs to be mapped to the chevereto container
It is customary to first create the -v parameter to mount the required folder:
mkdir -p /docker/chevereto/config mkdir -p /docker/chevereto/data
Deploy chevereto
The docker run formula command is as follows:
docker run --name=chevereto -d --restart=always \ -p 8090:80 \ #Map the host port to port 80 in the container. Please modify it according to your actual situation -e TZ=Asia/Shanghai \ #Set the container time zone -v /docker/chevereto/config:/config \ #Map the host specified folder to the /config directory in the container -v /docker/chevereto/data:/data \ #Map the host specified folder to the /data directory in the container linuxserver/chevereto:latest
In addition: If you want to use it with PicGo and an editor (such as obsidian) to realize the automatic upload function of copying and pasting pictures, you also need a line of -v parameter:
-v /docker/chevereto/config/route.api.php:/app/chevereto/app/routes/route.api.php
However, you need to create a container first./app/chevereto/app/routes/route.api.php
Files are copied from the container to the host machine/docker/chevereto/config
Directory, then delete the container, re-add this line of -v parameters to re-create the container, you can refer to the following docker command:
docker cp chevereto:/app/chevereto/app/routes/route.api.php /docker/chevereto/config
Note: Please delete the comment after #
Initialize chevereto
passhttp://host ip:8090
To log in:
The above information is filled in according to the information when initializing the database. If the database configuration is correct, the following interface will be displayed:
After the configuration is complete, click "install Chevereto" at the bottom to complete the installation. After success, the following interface will be displayed:
At this point, the chevereto installation is complete. Click "admin dashboard" in the red box to jump to the login interface:
Log in using the admin username and password configured previously:
Click "Settings" in the red box above:
"HTTPS" specifies whether chevereto's external links should use http or https. The default is "Automatic", and you can also choose "Disabled" and "Forced". "Default time zone" is used to specify the time zone. For China, just change it to "Asia/Shanghai". Finally, remember to click "Save changes" in the red box at the bottom to save the changed configuration.
One thing that needs to be emphasized in this interface is the "HTTPS" option. The default is Automatic, which will automatically detect https and is also the recommended option. However, in actual use, when I accessed it with https through a reverse proxy, I encountered the following display:
It is different from the login interface we saw earlier. This is because the request returned by chevereto received by the browser is http, not https. This is normal because the address of the chevereto container pointed to by the reverse proxy is also http. Therefore, chevereto detects http requests sent by the reverse proxy. Through this "Automatic", only http can be detected, so the returned address is http.
There are two solutions to solve the above problems:
1. Directly modify the "HTTPS" option of chevereto to "Forced"
This is the simplest method. If the actual external addresses of the image hosting service are all https through the reverse proxy, then there is no problem in selecting "Forced". However, if some are https and some are http, for example, there are 2 external domain names, corresponding to 2 reverse proxies, one of which is https and the other is http, in this case, "Forced" cannot be selected, and you can only select "Disabled" or "Automatic". In this case, you can only configure it on the reverse proxy in https mode to solve the problem, see the next section.
2. Configure on the reverse proxy
Configure it on the reverse proxy that is https externally. If it is nginx, you need to add a line to the reverse proxy configuration. You can refer to my other article:Docker series solves the problem that chevereto is deployed behind a reverse proxy and works abnormally.
Create an album
Click the account name "Admin" in the red box in the upper right corner, and select "Albums" in the red box from the drop-down menu:
The following interface appears:
Click "Create new album" in the red box above:
In the picture above, you can fill in any name of the album. I named it blog because this album is used to store pictures in articles in the blog. The key is "Album privacy", that is, the album privacy option. The default is Public. Because this album is for pictures in the blog, I set it to private (anyone can access it with a link). The first album created has an id of 1. This is needed when used with other apps, such as with PicGo to achieve automatic upload of screenshots and pastes, and when setting up the chevereto uploader. If you create a new album later, you will have to look for the album id in chevereto when there are too many albums, so it is better to create the album for the main purpose at the beginning, so that the id is directly 1.
If it is an album created later, the id can be found in the album's Full info:
upload image
Uploading pictures is very simple. Just click the "upload" button in the red box in the upper right corner of any interface:
The following interface appears:
As can be seen from the two red boxes below, you can directly browse local images to add them, or add them through the URL of the online image. However, many image hosting services are set up to prevent hotlinks, so adding images using the URL may not work well. Taking adding from local as an example, batch adding is supported:
After selecting the picture, click Open in the lower right corner:
Select the blog you just created in the album, and then click "Upload" in the red box at the bottom to complete the upload:
Click on the "blog" link in the red box above:
You can see the pictures you just uploaded. Double-click any picture to enter it. You can see picture links in various formats at the bottom:
Just select the format you need.
Configuring public network access
To publish to the public Internet, you need to choose the most suitable publishing method according to the actual environment and the reverse proxy you use. You can refer to my previous articles:
1,Docker series uses Docker to build its own reverse proxy based on NPM
2,Linux panel series configure reverse proxy and use non-443 port for publishing
3.Home data center series uses domestic cloud hosting to get free cloudflare to achieve fast access to domestic sites from abroad
4.Home Data Center Series: Use cloudflare to build a website quickly with no public IP in your home broadband (general purpose)
The first and second methods are suitable for environments with public IP but no legal 443 port (home broadband, unregistered cloud host). You need to add a non-standard port after the URL (if you use cloudflare to build a website, you don't need to add a port, but you need to customize the source station port. You can refer to:Home data center series uses cloudflare's Origin Rules to solve the problem of having a public IP but no legal ports 80 and 443 when building a websiteThe third method is suitable for cloud hosts with a record, and the fourth method is suitable for all environments (including environments without public IP), which is also the method I recommend (regardless of whether your environment has a public IP or not, because this method does not require running https traffic directly on the public network).
Afterword
In fact, chevereto has a wealth of functional options (such as adding image watermarks, which can be found in my other article:How to add watermarks to images using chevereto), but due to space limitations I will not elaborate on this.
In addition, the image upload method in this article is the most basic way to use the image hosting service, but under normal circumstances, this method is too inefficient. If there are dozens of images in an article, this method will be very time-consuming. The most efficient way is to use an image upload app such as PicGo and use it with your editor to achieve direct pasting and automatic upload and automatically generate image links in the editor. This requires the use of the API. For specific configuration, see my other article:Chevereto+PicGo+Obsidian is a series of tricks to achieve efficient image upload and image URL acquisition.