Configuration

  • Ubuntu服务器11.10 64位
  • 亚马逊AWS,Ec2,托管在云上
  • t1.微实例

在我写其他东西之前,我想声明我已经判断了nginx 502 bad gatewayNginx + PHP-FPM 502 Bad Gateway个线程,不幸的是,这在这方面对我没有帮助.

这个问题似乎相当常见:nginx或php-fpm的错误配置可能会导致502 Bad Gateway错误,这是我一直无法解决的问题.请注意,它显示为even when I go to my domain root,没有指定任何特定的目录.

我运行的是一台Amazon EC2 Web服务器,端口9000已启用,端口80已打开,等等.

特别的问题是,我怎样才能摆脱这个令人讨厌的错误?或者,更好的是,我怎样才能得到php5-fpmactually work.

What I Have Attempted so Far

配置文件的编辑基本一致,特别是php-fpm.confnginx.conf.

i. php-fpm.conf

我添加了以下内容,但帮助不大:

;;;;;;;;;;;;;
; Fpm Start ;
;;;;;;;;;;;;;

;pm.start_servers = 20
;pm.min_spare_servers = 5
;pm.max_spare_servers = 35

现在,之后我try 包括我的配置文件:

include=/etc/php5/fpm/*.conf

这只会让我更难过.

Full Configuration

;;;;;;;;;;;;;;;;;;;;;
; FPM Configuration ;
;;;;;;;;;;;;;;;;;;;;;

; All relative paths in this configuration file are relative to PHP's install
; prefix (/usr). This prefix can be dynamicaly changed by using the
; '-p' argument from the command line.

; Include one or more files. If glob(3) exists, it is used to include a bunch of
; files from a glob(3) pattern. This directive can be used everywhere in the
; file.
; Relative path can also be used. They will be prefixed by:
;  - the global prefix if it's been set (-p arguement)
;  - /usr otherwise
;include=/etc/php5/fpm/*.conf

;;;;;;;;;;;;;;;;;;
; Global Options ;
;;;;;;;;;;;;;;;;;;

[global]
; Pid file
; Note: the default prefix is /var
; Default Value: none
pid = /var/run/php5-fpm.pid

; Error log file
; Note: the default prefix is /var
; Default Value: log/php-fpm.log
error_log = /var/log/php5-fpm.log

; Log level
; Possible Values: alert, error, warning, notice, debug
; Default Value: notice
log_level = notice

; If this number of child processes exit with SIGSEGV or SIGBUS within the time
; interval set by emergency_restart_interval then FPM will restart. A value
; of '0' means 'Off'.
; Default Value: 0
;emergency_restart_threshold = 0

; Interval of time used by emergency_restart_interval to determine when 
; a graceful restart will be initiated.  This can be useful to work around
; accidental corruptions in an accelerator's shared memory.
; Available Units: s(econds), m(inutes), h(ours), or d(ays)
; Default Unit: seconds
; Default Value: 0
emergency_restart_interval = 0

; Time limit for child processes to wait for a reaction on signals from master.
; Available units: s(econds), m(inutes), h(ours), or d(ays)
; Default Unit: seconds
; Default Value: 0
;process_control_timeout = 0

; Send FPM to background. Set to 'no' to keep FPM in foreground for debugging.
; Default Value: yes
daemonize = no

;;;;;;;;;;;;;
; Fpm Start ;
;;;;;;;;;;;;;

;pm.start_servers = 20
;pm.min_spare_servers = 5
;pm.max_spare_servers = 35

;;;;;;;;;;;;;;;;;;;;
; Pool Definitions ; 
;;;;;;;;;;;;;;;;;;;;

; Multiple pools of child processes may be started with different listening
; ports and different management options.  The name of the pool will be
; used in logs and stats. There is no limitation on the number of pools which
; FPM can handle. Your system will tell you anyway :)

; To configure the pools it is recommended to have one .conf file per
; pool in the following directory:
include=/etc/php5/fpm/pool.d/*.conf

一百点一零一

老实说,这种配置是我访问过的几个网站中的一小部分,但我可以告诉你,在502 Bad Gateway业务之前,服务器运行得很好(没有PHP工作).句号.).

问题主要在于某件事非常非常不对劲.现在,当我试着做一个service php5-fpm restart,它挂在一个无限循环或什么的,我甚至不能CTRL-C.

Full Configuration

user www-data;
worker_processes 1;
pid /var/run/nginx.pid;

events {
    worker_connections 64;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush off;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;

    server {
        listen 80;
        server_name ec2-xx-xx-xx-xx.compute-x.amazonaws.com;

        location ~ ^(.+\.php)(.*)$ {
            root   /home/wayvac/public;
            fastcgi_pass   unix:/var/run/php5-fpm.pid;  
            #fastcgi_pass   127.0.0.1:9000; #Un-comment this and comment "fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock;" if you are not using php-fpm.
            fastcgi_index  index.php;
            set $document_root2 $document_root;
            if ($document_root2 ~ "^(.*\\\\).*?[\\\\|\/]\.\.\/(.*)$") { set $document_root2 $1$2; }
            if ($document_root2 ~ "^(.*\\\\).*?[\\\\|\/]\.\.\/(.*)$") { set $document_root2 $1$2; }
            if ($document_root2 ~ "^(.*\\\\).*?[\\\\|\/]\.\.\/(.*)$") { set $document_root2 $1$2; }
            if ($document_root2 ~ "^(.*\\\\).*?[\\\\|\/]\.\.\/(.*)$") { set $document_root2 $1$2; }
            if ($document_root2 ~ "^(.*\\\\).*?[\\\\|\/]\.\.\/(.*)$") { set $document_root2 $1$2; }
            fastcgi_split_path_info ^(.+\.php)(.*)$;
            fastcgi_param   SCRIPT_FILENAME $document_root2$fastcgi_script_name;
            fastcgi_param   PATH_INFO   $fastcgi_path_info;
            fastcgi_param   PATH_TRANSLATED $document_root2$fastcgi_path_info;
            include fastcgi_params;
            fastcgi_param  DOCUMENT_ROOT      $document_root2;
        }       

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        location / {
            root /home/wayvac/public;   
            index index.html index.htm index.php;
        }

        location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
            # Some basic cache-control for static files to be sent to the browser
            expires max;
            add_header Pragma public;
            add_header Cache-Control "public, must-revalidate, proxy-revalidate";
        }

        #include drop.conf;
        #include php.conf;
    }
}

推荐答案

如果有人发现这一页遇到了和我相同的问题,我找到了答案here.

对于那些懒得点击并自己解决问题的人……;)

The Condition:

使用NGINX和PHP5.3的Ubuntu或Debian服务器运行良好,但将PHP升级到5.4会导致502个严重的网关错误.查找在端口9000上运行的服务(通常运行netstat -lp或类似端口)不会返回任何结果.

The fix:

打开/etc/php5/fpm/pool.d/www.conf并记下'listen'参数(在我的例子/var/run/php5-fpm.sock中):

; The address on which to accept FastCGI requests.
; Valid syntaxes are:
;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specific address on
;                            a specific port;
;   'port'                 - to listen on a TCP socket to all addresses on a
;                            specific port;
;   '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = /var/run/php5-fpm.sock

并将vhost中的fast cgi_pass变量替换为您刚才注意到的位置.

下面是symfony2配置示例(取自here):

  # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  location ~ ^/(app|app_dev)\.php(/|$) {
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;
    fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
    fastcgi_param  HTTPS              off;
  }

变成这样:

  # pass the PHP scripts to FastCGI server at /var/run/php5-fpm.sock
  location ~ ^/(app|app_dev)\.php(/|$) {
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;
    fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
    fastcgi_param  HTTPS              off;
  }

然后重新启动nginx:

sudo /etc/init.d/nginx restart

Note:如果您未使用SF2**,请将~ ^/(app|app_dev)\.php(/|$) {替换为~ ^/index\.php(/|$) {

希望这能节省一些时间:)

Edit

当然,您可以将/etc/php5/fpm/pool.d/www.conf中的listen = /var/run/php5-fpm.sock更改为listen = 127.0.0.1:9000,然后重新启动php5-fpm(这将使您不必更改vhost),但您必须假设他们将php5-fpm更改为通过套接字运行,而不是出于某种原因侦听9000端口.

Edit2

如果您仍然遇到502错误,请参阅此answer.

Php相关问答推荐

为WooCommerce中的特定用户角色指定促销价格

在AJX请求中使用简写后,FormData出现非法调用错误

获得客户S在WooCommerce为期1年的总支出

编写WooCommerce多步骤签出

如何将对我的域的请求重定向到子文件夹中的索引,同时保留域URL并使用.htaccess?

PHP原始数据读取引发max_input_vars错误

Laravel:测试命令时无法获取工作通知::AssertSentTo

根据WooCommerce购物车页面中的自定义 Select 添加费用

如何在微软图形API中使用用户S访问令牌或基于租户ID的访问令牌?

在php中,方法之间的属性链接是如何工作的

添加不存在的订单元数据以扩展WooCommerce管理订单搜索

添加不存在的订单元数据以扩展WooCommerce针对特定产品的管理订单搜索

防止 WooCommerce 在前端加载全尺寸图像

无法在 Laravel 中实例化抽象类 ProductAbstract

安装 Herd 并返回 Valet 后为 502

带有分类术语数组的 WordPress Elementor 自定义查询 - 如何要求所有术语都在返回的帖子中

根据WooCommerce中的产品重量更改简单产品的输入数量步值

从图像URL中获取文件扩展名?

如何在构建 PHP 类别数组树的递归函数中将父面包屑传递给子项?

PDO 和 SQL 查询结果中日期格式不同的原因可能是什么?