简体   繁体   中英

Run multiple nginx on one dedicated server ubuntu

Is it possible to run multiple NGINX on a single Dedicated server? I have a dedicated server with 256gb of ram, and I am running multiple PHP scripts on it but it's getting hangs because of memory used with PHP. when I check

free -m

it's not even using 1% of memory.

So, I am guessing its has some to do with NGINX.

Can I install multiple NGINX on this server and use them like

 5.5.5.5:8080,  5.5.5.5:8081,  5.5.5.5:8082

I have already allocated 20 GB memory to PHP, but still not working Properly.

Reason :- NGINX gives 504 Gateway Time-out

Either PHP or NGINX is misconfigured

You may run multiple instances of nginx on the same server provided that some conditions are met. But this is not the solution you should look for (also this may not solve your problem at all).

I got my Ubuntu / PHP / Nginx server set this way (it actually also runs some Node.js servers in parallel). Here is a configuration example which works fine on a AWS EC2 medium instance (m3).

upstream xxx {
#   server unix:/var/run/php5-fpm.sock;
    server 127.0.0.1:9000 max_fails=0 fail_timeout=10s weight=1;
    ip_hash;
    keepalive 512;
}

server {
    listen 80;
    listen 8080;
    listen 443 ssl;
    #listen [::]:80 ipv6only=on;

    server_name xxx.mydomain.io yyy.mydomain.io;
    if ( $http_x_forwarded_proto = 'http' ) {
        return 301 https://$server_name$request_uri;
    }

    root /home/ubuntu/www/xxxroot;
    index index.php;

    location / {
        try_files $uri $uri/ /index.php;
    }


    location ~ ^/(status|ping)$ {
        access_log off;
        allow 127.0.0.1;
        #allow 1.2.3.4#your-ip;
        #deny all;
        include fastcgi_params;
        fastcgi_pass 127.0.0.1:9000;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;

        fastcgi_pass adn;
        #fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /xxxroot/$fastcgi_script_name;
        fastcgi_param SCRIPT_FILENAME $request_filename;
#fastcgi_param DOCUMENT_ROOT /home/ubuntu/www/xxxroot;
        # send bad requests to 404
        #fastcgi_intercept_errors on;
        include fastcgi_params;
    }

    location ~ /\.ht {
            deny all;
    }

}

Hope it helps,

I think you are running into a timeout. Your PHP-Scripts seams to run to long.

Check following:

  • max_execution_time in your php.ini
  • request_terminate_timeout in www.conf of your PHP-FPM configuration
  • fastcgi_read_timeout in http section or location section of your nginx configuration.

Nginx is designed more to be used as a reverse proxy or load balancer than to control application logic and run php scripts. Running multiple instances of nginx that each execute php isn't really playing to the server application's strengths. As an alternative, I'd recommend using nginx to proxy between one or more apache instances, which are better suited to executing heavy php scripts. http://kbeezie.com/apache-with-nginx/ contains information on getting apache and nginx to play nicely together.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM