System Information
- Strapi Version: v4.5.3
- Operating System: Ubuntu 22.04
- Database: PostgreSQL 10.21
- Node Version: v16.18.0
- NPM Version: 8.19.2
- Yarn Version: n/a
I am having an issue I can not figure out. Any help is appreciated.
I followed the guide here to deploy to ec2. Per the guide, I am using pm2 to keep Strapi running. I have upgraded my installed version a few times and I keep getting the same error.
After I run:
NODE_ENV=production npm run build
I reboot to verify pm2 will bring the server back up. After the reboot, I check with:
pm2 log
Sometimes it works and everything is running perfectly.
Actions available
0|
0| | Welcome back!
0| | To manage your project 🚀, go to the administration panel at:
0| | https://mydomain/admin
0| |
0| | To access the server ⚡️, go to:
0| | https://mydomain
Sometimes I get:
Debug: Server wasn't able to start properly.
Error: The port 1337 is already used by another application.
Interestingly, despite the error the server is still running. If I reboot a few times, this goes away and the server starts up without issue. I suspect that it may have something to do with the reverse proxy configuration. If you spot something wrong, please tell me. If you need any more information to assist, please let me know.
My server.js file
module.exports = ({ env }) => ({
host: env('HOST', '0.0.0.0'),
port: env.int('PORT', 1337),
url: 'my domain here',
proxy: env.bool('IS_PROXIED', true),
app: {
keys: env.array('APP_KEYS'),
},
});
My nginx config, which I set up according to the guide here
# /etc/nginx/nginx.conf
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
# multi_accept on;
}
http {
server {
listen 80;
listen [::]:80;
server_name mydomain www.mydomain;
# Proxy Config
location / {
proxy_pass http://strapi;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_pass_request_headers on;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/mydomain/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/mydomain/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
#mail {
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
# server {
# listen localhost:110;
# protocol pop3;
# proxy on;
# }
#
# server {
# listen localhost:143;
# protocol imap;
# proxy on;
# }
#}