Hands-On Full Stack Web Development with Angular 6 and Laravel 5
上QQ阅读APP看书,第一时间看更新

Configuring nginx

Now, it's time to create the configuration files for the nginx and php-fpm servers, so we will be using the nginx reverse proxy to serve our PHP files to the web.

Inside the nginx folder, create a new file called nginx.conf and add the following code:

server {
listen 80 default;
client_max_body_size 308M;
access_log /var/log/nginx/application.access.log;
root /application/public;
index index.php;
if (!-e $request_filename) {
rewrite ^.*$ /index.php last;
}
location ~ \.php$ {
fastcgi_pass php-fpm:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
fastcgi_param PHP_VALUE
"error_log=/var/log/nginx/application_php_errors.log";
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
include fastcgi_params;
}
}

The previous file set port 80 as the default port for our web server and set port 9000 to php-fpm, which means that our containers in nginx will communicate with php-fpm through port 9000, and, for communicating with the web, will use the public view through port 80. Later on, in docker-compose.yml, we will configure the internal Docker container ports to the outside world, which, in this case, is our host machine.