Here are my configuration files


# 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
    location ~ \.php$ {
        # root  html;
        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;



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

  • What are you using for fastcgi and what do those configurations look like? – nojak Sep 2 '12 at 18:59

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 increasing pm.max_children and pm.max_requests.

If pm is set to dynamic, try upping the pm.start_servers, pm.min_spare_servers, and pm.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:

    ssl on;

    # For SSL caching
    ssl_session_cache shared:SSL:10m; 

    # For chained certs
    ssl_verify_depth 4; 

    ssl_certificate /etc/ssl/certs/cert.crt;
    ssl_certificate_key /etc/ssl/certs/privkey.pem;

    ssl_ciphers HIGH:!aNULL:!MD5;
    ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;

    ssl_session_timeout 5m;
    keepalive_timeout 70;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.