diff --git a/.travis.sh b/.travis.sh
index ab95ebbc..de43ce8e 100755
--- a/.travis.sh
+++ b/.travis.sh
@@ -3,7 +3,7 @@ set -xe
 if [ $TOX_ENV == "coverage" ]
 then
   pip install coveralls
-  tox -e py27
+  tox -e py27-unittests
   coveralls
 else
   tox -e $TOX_ENV
diff --git a/mkdocs/config.py b/mkdocs/config.py
index aeaad94e..2b6dcebe 100644
--- a/mkdocs/config.py
+++ b/mkdocs/config.py
@@ -97,6 +97,18 @@ def validate_config(user_config):
     if not config['site_name']:
         raise ConfigurationError("Config must contain 'site_name' setting.")
 
+    # Validate that the docs_dir and site_dir don't contain the
+    # other as this will lead to copying back and forth on each
+    # and eventually make a deep nested mess.
+    abs_site_dir = os.path.abspath(config['site_dir'])
+    abs_docs_dir = os.path.abspath(config['docs_dir'])
+    if abs_docs_dir.startswith(abs_site_dir):
+        raise ConfigurationError(
+            "The 'docs_dir' can't be within the 'site_dir'.")
+    elif abs_site_dir.startswith(abs_docs_dir):
+        raise ConfigurationError(
+            "The 'site_dir' can't be within the 'docs_dir'.")
+
     # If not specified, then the 'pages' config simply includes all
     # markdown files in the docs dir, without generating any header items
     # for them.

Don't allow the `site_dir` to be within the `docs_dir`
This leads to the output being copied into the output during a build.
diff --git a/mkdocs/tests/config_tests.py b/mkdocs/tests/config_tests.py
index b28d9465..4c27ec9a 100644
--- a/mkdocs/tests/config_tests.py
+++ b/mkdocs/tests/config_tests.py
@@ -111,3 +111,27 @@ class ConfigTests(unittest.TestCase):
             self.assertEqual(conf['pages'], ['index.md', 'about.md'])
         finally:
             shutil.rmtree(tmp_dir)
+
+    def test_doc_dir_in_site_dir(self):
+
+        test_configs = (
+            {'docs_dir': 'docs', 'site_dir': 'docs/site'},
+            {'docs_dir': 'site/docs', 'site_dir': 'site'},
+            {'docs_dir': 'docs', 'site_dir': '.'},
+            {'docs_dir': '.', 'site_dir': 'site'},
+            {'docs_dir': '.', 'site_dir': '.'},
+            {'docs_dir': 'docs', 'site_dir': ''},
+            {'docs_dir': '', 'site_dir': 'site'},
+            {'docs_dir': '', 'site_dir': ''},
+            {'docs_dir': '../mkdocs/docs', 'site_dir': 'docs'},
+        )
+
+        conf = {
+            'site_name': 'Example',
+        }
+
+        for test_config in test_configs:
+
+            c = conf.copy()
+            c.update(test_config)
+            self.assertRaises(ConfigurationError, config.validate_config, c)

pip install -e .
parse_log_pytest
requirements.txt
nose coverage pytest
apt-get update apt-get install -y gcc
3.4
requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
attrs==22.2.0
certifi==2021.5.30
coverage==6.2
ghp-import==2.1.0
importlib-metadata==4.8.3
iniconfig==1.1.1
Jinja2==3.0.3
Markdown==2.4.1
MarkupSafe==2.0.1
-e git+https://github.com/mkdocs/mkdocs.git@9b0aa1f87266f35c366ee2383987c6ba2f7b31d4#egg=mkdocs
nose==1.3.7
packaging==21.3
pluggy==1.0.0
py==1.11.0
pyparsing==3.1.4
pytest==7.0.1
python-dateutil==2.9.0.post0
PyYAML==6.0.1
six==1.17.0
tomli==1.2.3
typing_extensions==4.1.1
watchdog==2.3.1
zipp==3.6.0

name: mkdocs
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=21.2.2=py36h06a4308_0
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - attrs==22.2.0
      - coverage==6.2
      - ghp-import==2.1.0
      - importlib-metadata==4.8.3
      - iniconfig==1.1.1
      - jinja2==3.0.3
      - markdown==2.4.1
      - markupsafe==2.0.1
      - nose==1.3.7
      - packaging==21.3
      - pluggy==1.0.0
      - py==1.11.0
      - pyparsing==3.1.4
      - pytest==7.0.1
      - python-dateutil==2.9.0.post0
      - pyyaml==6.0.1
      - six==1.17.0
      - tomli==1.2.3
      - typing-extensions==4.1.1
      - watchdog==2.3.1
      - zipp==3.6.0
prefix: /opt/conda/envs/mkdocs

mkdocs/tests/config_tests.py::ConfigTests::test_doc_dir_in_site_dir
mkdocs/tests/config_tests.py::ConfigTests::test_config_option mkdocs/tests/config_tests.py::ConfigTests::test_empty_config mkdocs/tests/config_tests.py::ConfigTests::test_theme
mkdocs/tests/config_tests.py::ConfigTests::test_default_pages mkdocs/tests/config_tests.py::ConfigTests::test_missing_config_file mkdocs/tests/config_tests.py::ConfigTests::test_missing_site_name
.travis.sh mkdocs/config.py
.travis.sh mkdocs/config.py