500RMB求解codeigniter配置nginx问题
我在nginx配置重写机制,假如的配置的域名是:works.com (这个是随便取的,通过host重定向就可以了),我的项目在www下面,本来我输入works.com 会自动跳到http://works.com/admin/login,但是结果跳到了127.0.0.1/www/?admin/login这种结果,如果手动输入http://works.com/admin/login是可以正常的,但是js。css域名全是127.0.0.1/www开头,网上找过很多方法,都试过,没用,本人也刚接触CI,由于工作及,没那么多时间耽误。希望可以现实教下 server {listen 80;
server_namesky.com;
# server_namelocalhost;
root /Users/hai_1988/workspace/sky;#我的项目在sky下面,index。php也是在sky下面
index index.phpindex.html index.htm;
# location ~ .*\.(css|js|jpg|png|jpeg|gif)$ {
# root /Users/hai_1988/workspace/sky;
# }
location / {
# if (!-e $request_filename) {
# rewrite^/(.*)$ /sky/index.php?/$1 last;
# rewrite^/(.*)$ /index.php/$1 last;
# }
# indexindex.html index.htm index.php;
try_files $uri $uri/ /index.php?$query_string;
}
# location ~ \.php$ {
# send_timeout 60;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_indexindex.php;
# fastcgi_split_path_info ^(.+\.php)(.*)$;
# fastcgi_param PATH_INFO $fastcgi_path_info;
# fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;
#include fastcgi_params;
# }
# location ~ \.php($|/) {
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_indexindex.php;
# fastcgi_split_path_info ^(.+\.php)(.*)$;
# fastcgi_param PATH_INFO $fastcgi_path_info;
# fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;
# include fastcgi_params;
# }
# location ~ /\.ht {
# denyall;
# }
location /index.php{
fastcgi_pass127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME /Users/hai_1988/workspace/sky/index.php;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
includefastcgi.conf;
}
}
这上面是我用过的方法,有点乱
我的config.php
$config['base_url'] = 'http://sky.com/';
$config['index_page'] = '';
$config['uri_protocol'] = 'PATH_INFO';
然后每次输入http://sky.com/'的时候,如果没登录,它自动回跳转http://sky.com/auth/login 这个地址是正确的,但是它跳的是
http://127.0.0.1/sky/index.php?/auth/login 这个地址,我觉得是路由没重写
本地有个.htaccess
代码如下:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1
如果谁能帮我解答酬谢200元。只要把代码写出来,我去测试,成功后喔会联系你的,谢谢大家了 hai1988 发表于 2016-10-17 20:14
server {
listen 80;
server_namesky.com;
$config['uri_protocol'] = 'PATH_INFO';
然后每次输入http://sky.com/'的时候,如果没登录,它自动回跳转http://sky.com/auth/login 这个地址是正确的,但是它跳的是
http://127.0.0.1/sky/index.php?/auth/login 这个地址,我觉得是路由没重写
$config['uri_protocol'] = 'REQUEST_URI';
如果是nginx官方的配置我记得参数应该是 REQUEST_URI
location /statics { #这个用来访问静态文件
index index.html;
}
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
include fastcgi.conf;
}
其他的location就可以删了。试试吧 本帖最后由 Closer 于 2016-10-17 17:28 编辑
可以先提嘗試過的哪幾種方式
例如 $config['base_url'] 的實體網址路徑
或 view 端如何呼叫 js / css 的 url 路徑原始碼 Closer 发表于 2016-10-17 17:23
可以先提嘗試過的哪幾種方式
例如 $config['base_url'] 的實體網址路徑
或 view 端如何呼叫 js / css 的 ur ...
都试过了,我也在论坛找到一些其他的帖子研究,还是没改变结果 hai1988 发表于 2016-10-17 17:29
都试过了,我也在论坛找到一些其他的帖子研究,还是没改变结果
nginx 配置按照 nginx 官方 CodeIgniter 配置搞。如果你没做什么设置是不会自己乱跳转的。 Hex 发表于 2016-10-17 18:22
nginx 配置按照 nginx 官方 CodeIgniter 配置搞。如果你没做什么设置是不会自己乱跳转的。 ...
对的,我下载过官方的,很简单就搞定了,但是公司给了我一个成型的项目,我想在本地搭建它,就是跳转了,域名都变了 “不可思议” 发表于 2016-10-17 22:11
location /statics { #这个用来访问静态文件
index index.html;
}
谢谢,你这方法不行。 if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
break;
}
在server里加上这段东西试试看,同时建议把server_name 做成改成localhost(虽然没啥差别),我上次遇到的一个不能重写URL的问题就是用上面这段解决的,加上去以后重启下nginx试试看 hai1988 发表于 2016-10-17 20:14
server {
listen 80;
server_namesky.com;
.htaccess 这明显是 Apache,你用 nginx 当然是有问题的。
你这个成型的项目,你需要去线上把配置拿下来,完完全全还原服务器的环境是肯定可以的。
或者你就把项目主要内容打包发上来,我帮你看看。
页:
[1]
2