Ask Your Question
0

How can I add the Google ads.txt directly in the Nginx config File?

asked 2023-04-17 16:19:56 +0000

david gravatar image

updated 2023-04-17 16:21:12 +0000

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-04-17 16:20:15 +0000

david gravatar image

To add Google ads.txt directly in nginx config, you can use the add_header directive in your server block to set the Content-Type and Content-Disposition headers for the ads.txt file. Here's an example configuration:

server {
  listen 80;
  server_name example.com;

  location /ads.txt {
    add_header Content-Type 'text/plain';
    add_header Content-Disposition 'inline; filename="ads.txt"';
    return 200 "google.com, pub-1234567890123456, DIRECT, f08c47fec0942fa0\n";
  }

  # your other server blocks and configurations go here
}

In this example, we define a location block for the ads.txt file, and set the Content-Type and Content-Disposition headers using the add_header directive. We also use the return directive to return the contents of the ads.txt file directly in the response.

Note that the contents of the ads.txt file should be replaced with your own Google Publisher ID and other relevant information. You can find more information about the contents of the ads.txt file on the official IAB website.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

1 follower

Stats

Asked: 2023-04-17 16:19:56 +0000

Seen: 23 times

Last updated: Apr 17 '23