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.
Verify the file:
Visit https://yourdomain.com/ads.txt in a web browser to ensure that the file is correctly uploaded and accessible.
Also, please make sure the permission and ownership of the ads.txt is set to 775.
To change the ownership of the ads.txt file to peertube and www-data, and set the permissions to 775, follow these steps in the command-line interface (CLI):
Connect to your server:
Use SSH to connect to your PeerTube server if you're not already connected.
Example:
ssh your-username@your-server-ip
Navigate to the directory where the ads.txt file is located:
Example if your ads.txt file is in /var/www/peertube:
cd /var/www/peertube
Change the ownership of the ads.txt file:
You can use the chown command to set the ownership to peertube for the user and www-data for the group:
sudo chown peertube:www-data ads.txt
Change the file permissions to 775:
Use the chmod command to set the permissions:
sudo chmod 775 ads.txt
Explanation:
chown peertube:www-data sets the user to peertube and the group to www-data.
chmod 775 gives read, write, and execute permissions to the owner and group, and read and execute permissions to others.
You can verify the changes by using the ls -l command:
ls -l ads.txt
This will show the ownership and permissions of the file. It should display something like this:
-rwxrwxr-x 1 peertube www-data ... ads.txt
for a Nginx server, your Nginx configuration for PeerTube may not allowing access to the root directory or static files like ads.txt.
To resolve this, you will need to modify the Nginx configuration for your PeerTube instance to ensure that files in the root directory can be served.
Here's how you can do it:
1.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.
3.Save the file and exit:
In Nano, press CTRL+O to save the file and CTRL+X to exit.
4.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 if the ads.txt is now accessible:
Open a browser and go to https://yourdomain.com/ads.txt. It should now display the content of the ads.txt file.
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.
Please let me know if this is helpful to you, or if you need some help.