php - CodeIgniter 登录时不允许 Nginx 405

标签 php codeigniter ubuntu login nginx

我有一个用 CodeIgniter 编写的应用程序,可以在我的本地服务器 (MAMP) 上完美运行。
现在我正在尝试使用 Ubuntu 服务器 13.10,但是当我单击登录按钮时,我总是收到 405 错误。

问题截图。
http://i42.tinypic.com/14e3sjc.png
这是我的 nginx.conf 文件:

    user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    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;

    ##
    # nginx-naxsi config
    ##
    # Uncomment it if you installed nginx-naxsi
    ##

    #include /etc/nginx/naxsi_core.rules;

    ##
    # nginx-passenger config
    ##
    # Uncomment it if you installed nginx-passenger
    ##

    #passenger_root /usr;
    #passenger_ruby /usr/bin/ruby;

    ##
    # Virtual Host Configs
    ##

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


#mail {
#   # See sample authentication script at:
#   # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
# 
#   # auth_http localhost/auth.php;
#   # pop3_capabilities "TOP" "USER";
#   # imap_capabilities "IMAP4rev1" "UIDPLUS";
# 
#   server {
#       listen     localhost:110;
#       protocol   pop3;
#       proxy      on;
#   }
# 
#   server {
#       listen     localhost:143;
#       protocol   imap;
#       proxy      on;
#   }
#}

你有什么想法?

最佳答案

一些简单的调整将使它工作。首先在您的 codeigniter 配置文件中将您的索引页设置为空,并将您的 uri_protocol 设置为 REQUEST_URI .

$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI'; 

然后检查您的根位置。我的应用程序有一个斜杠,大多数示例 Codeigniter/nginx 服务器 block 也是如此。

最后在你的 try_files 行中,确保你去掉了 =404 部分,然后只剩下这个:try_files $uri $uri/ /index.php; .

如果你卡住了,下面是我的工作 nginx 站点文件(我的配置文件是 ubuntu 安装的库存)。
#Working server block below. 
server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /var/www/my_app/current/;
    index index.php;

    server_name staging.myapp.com;

    location / {
            # First attempt to serve request as file, then
            # as directory, but codeigniter will handle the 404.
            try_files $uri $uri/ /index.php;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
    #       # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
    }
}

关于php - CodeIgniter 登录时不允许 Nginx 405,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20363120/

相关文章:

php - 在巨大的表中存储 "tags"以提高速度的最佳方法

java - 找不到适合 jdbc :derby:<db-name> error on JDBC with Java DB on Linux/Ubuntu 的驱动程序

python - 如何将数据保存到 csv Cantera 和错误 <cantera.composite.SolutionArray object at 0x7f4badca0fd0>

php - 如果条件在另一表中为真,如何允许在一个表中输入内容。 - mysql

php - 使用 PHP 批量输入 SQL 行

php - 如何设置正确的codeigniter base url?

javascript - 如何使用 JQuery 验证 Ckeditor

php - 多个组织的系统设计

php - 在 PHP 上安装 Lapack

javascript - 如何使用 jQuery 在页面加载时找到选定的单选按钮?