我有一个用 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/