To add the ads.txt file for Google AdSense on your PeerTube website, follow these steps:
Create the ads.txt file:
Open a text editor and create a new file named ads.txt.
Inside the file, add the necessary AdSense information provided by Google (usually something like google.com, pub-xxxxxxxxxxxxxxxx, DIRECT, f08c47fec0942fa0).
Upload ads.txt to the root of your PeerTube domain:
Access your PeerTube server via FTP or SSH.
Navigate to the web root directory (usually something like /var/www/peertube or wherever your web files are stored).
Place the ads.txt file in the root directory so that it is accessible via https://yourdomain.com/ads.txt.
check the ownership and permission of the upload ads.txt file
ls -l ads.txt
if the ownership is not the same as the other listed file in the same root, or the permission is not -rwxrwxr-x, you may want to make a change:
sudo chown peertube:www-data ads.txt
sudo chmod 775 ads.txt
Then check again with:
ls -l ads.txt
or
ls -l
make changes in the nginx conf file:
Edit the Nginx configuration file:
The PeerTube Nginx configuration file is usually located in /etc/nginx/sites-available/ or /etc/nginx/conf.d/.
Open the configuration file using a text editor. For example, if your config file is in /etc/nginx/sites-available/peertube:
sudo nano /etc/nginx/sites-available/peertube
Check or Add a rule to serve the ads.txt file:
You need to ensure that Nginx is serving the ads.txt file from the root directory. Look for the following block (or add it) within your server block in the Nginx config:
nginx
location /ads.txt {
root /var/www/peertube;
}
This configuration tells Nginx to serve the ads.txt file from the /var/www/peertube directory.
Save the file and exit:
In Nano, press CTRL+O to save the file and CTRL+X to exit.
Test the Nginx configuration:
Before reloading Nginx, it's important to test the configuration for any errors:
sudo nginx -t
If there are no errors, you should see something like:
nginx: configuration file /etc/nginx/nginx.conf test is successful
- Reload Nginx:
After confirming that the configuration is correct, reload Nginx to apply the changes:
sudo systemctl reload nginx
Verify the file:
Visit https://yourdomain.com/ads.txt in a web browser to ensure that the file is correctly uploaded and accessible.
Once done, Google will automatically scan the file as part of their regular updates. This should allow Google AdSense to validate your ads and continue serving them appropriately.