Here are my configuration files
ssl.conf
# HTTPS server
#
server {
listen 443 ssl;
server_name api.domain.com;
error_log /var/log/nginx/api.error.log;
location / {
root /var/www/api.domain.com;
index index.html index.php index.php;
try_files $uri $uri/ /index.php?$args;
}
ssl on;
ssl_certificate /etc/nginx/api.domain.com.crt;
ssl_certificate_key /etc/nginx/api.domain.com.key;
ssl_session_timeout 5m;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
# root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param SCRIPT_FILENAME /var/www/api.domain.com$fastcgi_script_name;
fastcgi_param HTTPS on;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
nginx.conf
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
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"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
include /etc/nginx/conf.d/*.conf;
}
I have a server running on port 80 that runs with no issues. As soon as I turn on this api server running on ssl, it works for about a minute and then crashes and gives a 504 Gateway Time-out.
Running nginx/1.2.3
Best Answer
Gateway timeouts in NGiNX are usually caused by problems with fastcgi (e.g.
spawn_fcgi
,php-fpm
).Make sure it's running and listening.
If you're using
php-fpm
, try increasingpm.max_children
andpm.max_requests
.If
pm
is set todynamic
, try upping thepm.start_servers
,pm.min_spare_servers
, andpm.max_spare_servers
.If you're still having issues after that, try adding shared SSL session caching and increasing your worker processes to the number of CPU cores you have in NGiNX.
Example of SSL settings: