Skip to content

Commit

Permalink
fix(robots.txt): add config serving bots
Browse files Browse the repository at this point in the history
  • Loading branch information
ojeytonwilliams authored and raisedadead committed Jan 3, 2025
1 parent 8801daa commit 07118dd
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 14 deletions.
3 changes: 3 additions & 0 deletions sites-enabled/10-www.freecodecamp.org.conf
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,9 @@ server {
# additional config
include snippets/common/general.conf;

# robots config
include snippets/common/robots-org.conf;

# error page
error_page 503 @maintenance;
location @maintenance {
Expand Down
4 changes: 4 additions & 0 deletions sites-enabled/11-api.freecodecamp.org.conf
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ server {

# additional config
include snippets/common/general.conf;

# robots config
include snippets/common/robots-org.conf;

}

# HTTP redirect
Expand Down
3 changes: 3 additions & 0 deletions sites-enabled/15-chinese.freecodecamp.org.conf
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ server {
# additional config
include snippets/common/general.conf;

# robots config
include snippets/common/robots-org.conf;

# error page
error_page 503 @maintenance;
location @maintenance {
Expand Down
8 changes: 3 additions & 5 deletions sites-enabled/20-www.freecodecamp.dev.conf
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@ server {
add_header Content-Type text/plain;
}

# Do not index on search engines
location /robots.txt {
return 200 "User-agent: YandexDisallow: /\nUser-agent: *\nDisallow: /";
}

# redirect /forum/ and /forum to subdomain
rewrite ^/forum(?:|/(.*))$ https://forum.freecodecamp.dev/$1 permanent;

Expand Down Expand Up @@ -234,6 +229,9 @@ server {

# additional config
include snippets/common/general.conf;

# robots config
include snippets/common/robots-dev.conf;

# error page
error_page 503 @maintenance;
Expand Down
9 changes: 4 additions & 5 deletions sites-enabled/21-api.freecodecamp.dev.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ server {
# security
include snippets/common/security.conf;

# Do not index on search engines
location /robots.txt {
return 200 "User-agent: YandexDisallow: /\nUser-agent: *\nDisallow: /";
}

# reverse proxy api
location / {
# Do not index on search engines
Expand All @@ -33,6 +28,10 @@ server {

# additional config
include snippets/common/general.conf;

# robots config
include snippets/common/robots-dev.conf;

}

# HTTP redirect
Expand Down
7 changes: 3 additions & 4 deletions sites-enabled/30-chinese.freecodecamp.dev.conf
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ server {
add_header Content-Type text/plain;
}

location /robots.txt {
return 200 "User-agent: YandexDisallow: /\nUser-agent: *\nDisallow: /";
}

# reverse proxy news - Ghost
location ^~ /news/ghost/api/v3/admin/snippets/ {
return 500;
Expand All @@ -51,6 +47,9 @@ server {
# additional config
include snippets/common/general.conf;

# robots config
include snippets/common/robots-dev.conf;

# error page
error_page 503 @maintenance;
location @maintenance {
Expand Down
9 changes: 9 additions & 0 deletions snippets/common/general.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@ location = /favicon.ico {
access_log off;
}

map $host $robots_txt {
www.freecodecamp.org "etc/nginx/snippets/files/10-www.freecodecamp.org.robots.txt";
default "etc/nginx/snippets/files/00-default.robots.txt";
}

# robots.txt
location = /robots.txt {
alias $robots_txt;
expires 15d;
add_header Cache-Control "public";

log_not_found off;
access_log off;
}
Expand Down
2 changes: 2 additions & 0 deletions snippets/files/00-default.robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
User-Agent: *
Disallow: /
20 changes: 20 additions & 0 deletions snippets/files/10-www.freecodecamp.org.robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
User-Agent: *
Allow: /
Disallow: /learn

User-agent: GPTBot
Disallow: /

User-agent: ChatGPT-User
Disallow: /

User-agent: anthropic-ai
Disallow: /

User-agent: Google-Extended
Disallow: /

User-agent: Bytespider
Disallow: /

Sitemap: https://www.freecodecamp.org/news/sitemap.xml

0 comments on commit 07118dd

Please sign in to comment.