Reputation: 445
I am running nginx on the server and not within a docker container because of troubles with getting a working SSL. I have a docker container set up separately running my-sql and php-fpm. When I have all this running I get file not found and I can't work out why.
When I run sudo nginx -t
it says everything is fine but I still get file not found
after I run sudo systemctl restart nginx
My Nginx file:
server {
listen 80;
listen [::]:80;
server_name njord-assets.com www.njord-assets.com;
client_max_body_size 108M;
access_log /var/log/nginx/application.access.log;
root /var/www/njord-assets.com/public;
index index.php;
if (!-e $request_filename) {
rewrite ^.*$ /index.php last;
}
location ~ \.php$ {
fastcgi_pass localhost: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;
}
}
server {
listen 443 ssl;
server_name njord-assets.com www.njord-assets.com;
ssl_certificate /etc/letsencrypt/live/njord-assets.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/njord-assets.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/njord-assets.com/chain.pem;
client_max_body_size 108M;
access_log /var/log/nginx/application.access.log;
root /var/www/njord-assets.com/public;
index index.php;
if (!-e $request_filename) {
rewrite ^.*$ /index.php last;
}
location ~ \.php$ {
fastcgi_pass localhost: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;
}
}
Docker-compose file:
###############################################################################
# Generated on dev.io #
###############################################################################
version: "3.1"
services:
redis:
restart: always
image: redis:alpine
container_name: my-asset-management-redis
mysql:
restart: always
image: mysql:8.0
container_name: my-asset-management-mysql
working_dir: /application
volumes:
- .:/application
- mysql-data:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=app
- MYSQL_USER=user
- MYSQL_PASSWORD=pass
php-fpm:
restart: always
build: docker/production/php-fpm
container_name: my-asset-management-php-fpm
working_dir: /application
volumes:
- .:/application
- ./docker/production/php-fpm/php-ini-extras.ini:/etc/php/7.4/fpm/conf.d/99-extras.ini
ports:
- "9000:9000"
I have checked and my Nginx error logs are returning
2020/05/31 10:50:50 [error] 932#932: *570 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 81.149.1.9, server: njord-assets.com, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "njord-assets.com"
Upvotes: 2
Views: 1306
Reputation: 445
The problem was that the nginx file needed to have the root be the root within the container and not outside so this:
root /var/www/njord-assets.com/public;
should be:
root /application/public;
Upvotes: 1