Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Here are my configuration files


# HTTPS server
server {
    listen       443 ssl;
    error_log    /var/log/nginx/api.error.log;

    location / {
    root /var/www/;
    index index.html index.php index.php;
    try_files $uri $uri/ /index.php?$args;

    ssl                  on;
    ssl_certificate      /etc/nginx/;
    ssl_certificate_key  /etc/nginx/;

    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/$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/;

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

share|improve this question
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;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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