Deployment fails when custom nginx.conf points to a specific file in conf.d

0

I am running Craft CMS 3 via php Beanstalk instances, and using nginx partials https://github.com/nystudio107/nginx-craft (with some minor modifications) for the nginx config. I can confirm my configuration, stored in .platform folder works properly: the issue only comes up when provisioning an empty/new EC2 instance with my app package.

This is the error in the logs: 2020/06/26 10:14:23 [emerg] 3653#0: open() "/etc/nginx/conf.d/nginxpartials/security.conf" failed (2: No such file or directory) in /var/proxy/staging/nginx/nginx.conf:162

It's fairly clear the reason this is happening is the nginx configuration is verified and the deployment fails before the files in .platform/nginx/conf.d are copied over. If I delete the custom nginx.conf and deploy, then restore the same file and deploy this 2nd version of the package, the deployment works as expected. I believe this is a bug on AWS's side, but if anyone can advise a workaround I'd be very grateful.

Aroes
asked 4 years ago542 views
1 Answer
0

Hey there,

Craft CMS developer here! I've been working towards transitioning to AL2 and ran into this problem as well. The trick I used was to store the nginx partials in the conf.d folder.

In fact, I went ahead and structured my setup akin to Laravel Forge. So my folder structure looks like this:

.platform/
- after/
- before/
- partials/
- - compression.conf
- - expires.conf
- - security.conf
- sites-enabled
- - default.conf
- nginx.conf

My nginx.conf ends up looking like this:

#Elastic Beanstalk Nginx Configuration File

user                    nginx;
pid                     /var/run/nginx.pid;
worker_processes        auto;
worker_rlimit_nofile    66485;

events {
    worker_connections  1024;
}

http {
    map $http_upgrade $connection_upgrade {
        default     "upgrade";
    }
    
    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    include       conf.d/*.conf;

    include conf.d/before/*;
    include conf.d/sites-enabled/*;
    include conf.d/after/*;
}

and my default.conf is fairly standard, but with:

    # System level server mods
    include conf.d/server/*;

    # Load configuration files from nginx-partials
    include conf.d/partials/*.conf;

Feel free to hit me up on the Craft CMS discord (@Ransom) if you need anymore help.

answered 4 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions