2014-02-12 100 views
2

的nginx的配置如下:nginx的笨502網關

server { 
     listen  80; 
     server_name www.example.com; 

     root /home/wwwroot/example.com; 
     index index.php index.html index.htm; 

     location/{ 
       index index.php index.html index.htm; 
     } 

     location ~ \.php($|/) { 
      fastcgi_pass 127.0.0.1:9000; 
      fastcgi_index index.php; 
      fastcgi_split_path_info ^(.+\.php)(.*)$; 
      fastcgi_param PATH_INFO $fastcgi_path_info; 
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
      include  fastcgi_params; 
     } 

     if (!-e $request_filename) { 
      rewrite ^/(.*)$ /index.php/$1 last; 
      break; 
     } 

     location ~ /\.ht { 
       deny all; 
     } 
} 

,請給我一些建議,謝謝〜

+0

你在哪裏得到應用根'502壞gateway'? –

+0

是的,在應用程序根目錄 – Charles0429

+0

@RahilWazir在應用程序根目錄 – Charles0429

回答

3

我終於把自己弄對了。

server { 
    listen  80; 
    server_name example.com; 

    root /home/wwwroot/example.com; 
    index index.php index.html index.htm; 

    location/{ 
    root /home/wwwroot/example.com; 
      index index.php index.html index.htm; 
     if (!-e $request_filename) { 
       rewrite ^/(.*)$ /index.php/$1 last; 
       break; 
     } 
    } 
    location ~ \.php($|/) { 
     fastcgi_pass unix:/tmp/php-cgi.sock; 
     fastcgi_index index.php; 
     fastcgi_split_path_info ^(.+\.php)(.*)$; 
     fastcgi_param PATH_INFO $fastcgi_path_info; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     include  fastcgi_params; 
    } 
    location ~ /\.ht { 
      deny all; 
    } 
} 
0
  • 您不必在location /根(本可能是好的)

  • 你還沒有說明你是否試圖從url中刪除index.php(如果你試圖訪問沒有index.php的URL並且不重寫,這可能導致502)

  • 你缺少一些建議PARAMS

這裏是我已經運行並與CI工作Nginx上配置版本(CentOS 6)。它從URL中刪除index.php。這也是SSL,但如果你不需要,你可以把那些垃圾拿出來。它至少應該指出你在正確的方向。

server { 
    listen  80; 
    server_name _; 
    access_log /var/www/https/logs/access.log; 
    error_log /var/www/https/logs/error.log; 
    return  301 https://www.example.com$request_uri; 
} 

server { 
    listen 443 default_server ssl; 
    server_name *.example.com; 
    ssl on; 
    ssl_certificate /var/www/ssl/wildcard.example.com.chained.crt; 
    ssl_certificate_key /var/www/ssl/wildcard.example.com.key; 
    ssl_verify_depth 3; 
    access_log /var/www/https/logs/ssl/access.log; 
    error_log /var/www/https/logs/ssl/error.log; 

    #http://mailman.nginx.org/pipermail/nginx-announce/2013/000125.html 
    if ($request_uri ~ " ") { 
     return 444; 
    } 

    location/{ 
     root /var/www/https/; 

     # file doesn't exist, let CI handle it 
     if (!-f $request_filename) { 
       rewrite ^(.*) /index.php?$1 last; 
     } 
    } 

    location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico)$ { 
     root    /var/www/https/; 
     access_log  on; 
     expires   30d; 
    } 

    location ~ \.php$ { 
     include fastcgi.conf;#/etc/nginx/fastcgi.conf 
     fastcgi_param SCRIPT_FILENAME /var/www/https$fastcgi_script_name; 
    } 
} 


/etc/nginx/conf.d/fastcgi.conf: 

fastcgi_pass 127.0.0.1:9000; 
fastcgi_index index.php; 
fastcgi_split_path_info ^(.+\.php)(.*)$; 
fastcgi_param QUERY_STRING $query_string; 
fastcgi_param REQUEST_METHOD $request_method; 
fastcgi_param CONTENT_TYPE $content_type; 
fastcgi_param CONTENT_LENGTH $content_length; 

fastcgi_param SCRIPT_NAME $fastcgi_script_name; 
fastcgi_param REQUEST_URI $request_uri; 
fastcgi_param DOCUMENT_URI $document_uri; 
fastcgi_param DOCUMENT_ROOT $document_root; 
fastcgi_param PATH_INFO $fastcgi_path_info; 
fastcgi_param SERVER_PROTOCOL $server_protocol; 

fastcgi_param GATEWAY_INTERFACE CGI/1.1; 
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; 

fastcgi_param REMOTE_ADDR $remote_addr; 
fastcgi_param REMOTE_PORT $remote_port; 
fastcgi_param SERVER_ADDR $server_addr; 
fastcgi_param SERVER_PORT $server_port; 
fastcgi_param SERVER_NAME $server_name; 

# PHP only, required if PHP was built with --enable-force-cgi-redirect 
fastcgi_param REDIRECT_STATUS 200; 

fastcgi_connect_timeout 60; 
fastcgi_send_timeout 180; 
fastcgi_read_timeout 180; 
fastcgi_buffer_size 128k; 
fastcgi_buffers 4 256k; 
fastcgi_busy_buffers_size 256k; 
fastcgi_temp_file_write_size 256k; 
fastcgi_intercept_errors on; 

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
1

我在Codeigniter + nginx上也出現這個錯誤,但是我通過改變代碼解決了這個問題。 問題出在會議上。在會議中,我保存了stdClass對象。當我更改值或從會話檢索值時,它會給我502壞的網關。所以我將會話值更改爲關聯陣列然後我的問題就解決了。我認爲會話存儲值超過這就是爲什麼服務器給出了錯誤502壞的網關。

+0

是的建議也適用於我 –

0

請將以下行添加到Nginx的配置文件/etc/nginx/nginx.conf

http { 
    ... 
    fastcgi_buffers 8 16k; 
    fastcgi_buffer_size 32k; 
    ... 
} 

reference