2017-02-16 227 views
0

是否可以在一臺專用服務器上運行多個NGINX? 我有一個專用的服務器,內存爲256GB,而且我正在運行多個PHP腳本,但由於PHP使用的內存而導致掛起。 當我檢查在一臺專用服務器上運行多個nginx ubuntu

free -m 

它甚至沒有使用的內存的1%。

所以,我猜它與NGINX有一些關係。

我可以在此服務器上安裝多個NGINX,並利用它們像

5.5.5.5:8080, 5.5.5.5:8081, 5.5.5.5:8082 

我已撥出20 GB內存PHP,但仍然無法正常工作。

原因: - NGINX給504網關超時

+0

出於純粹的興趣,你爲什麼要運行多個網絡服務器? – RiggsFolly

+1

我建議追查內存錯誤。 20GB有很多內存,所以還有一個問題正在進行。 – aynber

+0

@RiggsFolly因爲一個NGINX給出了504錯誤.... – Harinder

回答

0

我得到了我的Ubuntu/PHP/Nginx的服務器設置這種方式(實際上它也運行一些Node.js的服務器將並行)。以下是一個配置示例,可在AWS EC2介質實例(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; 
    } 

} 

希望它能幫助,

0

我認爲你正在運行到超時。你的PHP腳本的接縫運行時間很長。

檢查以下內容:

  • max_execution_time在php.ini
  • 在你的PHP-FPM配置
  • fastcgi_read_timeoutwww.confrequest_terminate_timeouthttp部分或你的nginx配置location部分。
0

Nginx設計更多用作反向代理或負載均衡器,而不是控制應用程序邏輯並運行php腳本。運行每個執行php的nginx的多個實例並沒有真正發揮服務器應用程序的優勢。作爲替代,我建議使用nginx在一個或多個apache實例之間進行代理,這更適合執行繁重的php腳本。 http://kbeezie.com/apache-with-nginx/包含有關獲取apache和nginx在一起播放的信息。

+0

nginx是一個優秀的網絡服務器 – Paolo

1

PHP或NGINX配置錯誤

您可能會提供一些條件得到滿足在同一臺服務器上運行Nginx的多個實例。但這不是您應該尋找的解決方案(也可能根本無法解決您的問題)。