今天在mac上配置nginx+codeigniter的开发环境,在配置nginx的时候发生了奇怪的现象,就是http://localhost/cn/cgi(我的项目路径)总是显示404。我更改了无数次,看了大概几十篇博客,都未能解决这个奇怪的问题。今天特意把这个解决方案记下来,为的就是让自己以后遇到了能多一种思路:重启大法。我在下面贴出自己的nginx配置(当然问题不是出在nginx上,在这里贴出来只是给大家看看当时试了多少次~):
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
charset utf8;
root /usr/local/var/www/BackApi/frontend;
location / {
index index.html index.php;
}
location ~ \.php($|/) {
root /usr/local/var/www/BackApi/frontend;
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;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
# location / {
# index index.php;
# try_files $uri $uri/ /index.php?$uri&$args;
# }
#include enable-php-pathinfo.conf;
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
break;
}
# access_log /usr/local/nginx/logs/test.platform.access.log;
# error_log /usr/local/nginx/logs/test.platform.error.log;
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
include servers/*;
}
是的,试了多种方式之后,无奈重启,发现错误竟然消失了。。
原来重启不是一个梗,可能mac和nginx之间兼容性有点问题,我的nginx服务并没有如我的意去重启,所以我的配置一直不能生效。
为什么记录下来呢,真的是有的时候还可以试一下这个方法,说不定你的问题就飞走了。。真的,我花了一天看这个东西,没想到是重启解决了它。如果朋友们试了网上其他的种种方法还是不行的话,试试重启吧。:)