nginx的配置如下:
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 :(得分: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;
}
}
答案 1 :(得分:2)
请将以下行添加到Nginx配置文件/etc/nginx/nginx.conf
http {
...
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;
...
}
答案 2 :(得分:1)
我在Codeigniter + nginx上也遇到了这个错误,但我通过更改代码解决了这个问题。 问题在于会话。在Session中我保存了 stdClass对象。当我更改值或从会话中检索值时,它给我502坏网关。所以我将会话值更改为关联数组然后我的问题就解决了。我认为会话存储值超过这就是服务器给出错误502错误网关的原因。
答案 3 :(得分:0)
location /
中没有根(这可能没问题)
您尚未说明是否要尝试从网址中删除index.php
(如果您尝试访问没有index.php
的网址并且没有重写,则可能会导致到502)
您缺少一些建议的参数
这是我运行并使用CI(CentOS 6)的nginx配置。它从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;