I am trying to containerise and run my website on a PHP webserver with an nginx conf file (site.conf) and docker-compose.yml file. When I go to localhost:8080 I get the default nginx welcome page instead of the my index.html file. and When I go to php-docker.local:8080 I get a “this site cannot be reached message”.
Code Section
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Font Awesome icons (free version)-->
<script src="https://use.fontawesome.com/releases/v6.1.0/js/all.js" crossorigin="anonymous"></script>
<title>Registration</title>
<link rel="stylesheet" href="css/styles.css">
<link rel="icon" type="image/x-icon" href="assets/favicon.ico" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
</head>
<body class="container">
<div class="container">
<h1>Registration</h1>
<section>
<form id="regForm" action="form.php" method="post">
<div class="form-group">
<label for="nameInput">Name</label>
<input type="text" class="form-control" id="nameInput" name="studentName" aria-describedby="emailHelp" placeholder="Enter your full name">
</div>
<div class="form-group">
<label for="loginInput">Login</label>
<input type="text" class="form-control" id="loginInput" name="studentId" placeholder="Enter your login">
</div>
<button type="submit" name="submit" value="submit" class="btn btn-primary" id="submitForm">Submit</button>
</form>
</section>
</div>
<script src="js/regForm.js"></script>
<!-- Datatable -->
<!-- <script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.12.1/js/jquery.dataTables.js"></script> -->
<!-- <script src="https://cdn.startbootstrap.com/sb-forms-latest.js"></script> -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>
</html>
PHP
<?php
echo "Submitted";
if(isset($_POST['submit'])) {
$data = '';
$filename = "data.json";
//if file exists
if(is_file($filename)) {
$data = file_get_contents($filename);
}
$json_arr = json_decode($data,true);
$json_arr[] = array(
'studentId' => $_POST['studentId'],
'studentName' => $_POST['studentName'],
);
file_put_contents($filename, json_encode($json_arr));
}
?>
docker-compose.yml
version: '3'
services:
web:
image: nginx:latest
volumes:
- ./src:/src
- ./site.conf:/etc/nginx/conf.d/site.conf
ports:
- "8080:80"
links:
- php
php:
image: php:7-fpm
site.conf (nginx conf file)
server {
index index.html;
server_name php-docker.local;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /src;
}
file/folder structure
-form
-src
-index.html
-form.php
-docker-compose.yml
-site.conf
*** localhost Output ***
localhost:8080
php-docker.local:8080

