在Nginx中没有.htaccess(Mod_Rewrite)。所以我把我的.htaccess转换成可以读取并放在default.conf中的格式。
原始htaccess:
Options -Indexes RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* index.php?/$0 [PT,L]
将htaccess转换为Nginx格式:
# nginx configuration autoindex off; location / { if (!-e $request_filename){ rewrite ^(.*)$ /index.php?/$0 break; } }
正确…即时问题在那里.. Nginx不支持参数$ 0, 所以我已经改变了这个$ uri
问题我现在有..当我访问我的网站http://vibeshed.com/admin我得到下面的结果:(顺便说一句,我只是下载文件,但我删除了默认的MIMEtypes)。
见图:
任何帮助?
我的网站default.conf是:
# # The default server # server { listen 80; server_name vibeshed.com; location / { root /usr/share/nginx/html; index index.php index.html index.htm; autoindex on; if (!-e $request_filename){ rewrite ^(.*)$ /index.php?/$uri break; } } error_page 404 /404.html; location = /404.html { root /usr/share/nginx/html; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { root /usr/share/nginx/html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
我的Nginxconfiguration是:
####################################################################### # # This is the main Nginx configuration file. # # More information about the configuration options is available on # * the English wiki - http://wiki.nginx.org/Main # * the Russian documentation - http://sysoev.ru/nginx/ # ####################################################################### #---------------------------------------------------------------------- # Main Module - directives that cover basic functionality # # http://wiki.nginx.org/NginxHttpMainModule # #---------------------------------------------------------------------- user nginx; worker_processes 4; error_log /var/log/nginx/error.log; #error_log /var/log/nginx/error.log notice; #error_log /var/log/nginx/error.log info; pid /var/run/nginx.pid; #---------------------------------------------------------------------- # Events Module # # http://wiki.nginx.org/NginxHttpEventsModule # #---------------------------------------------------------------------- events { worker_connections 1024; } #---------------------------------------------------------------------- # HTTP Core Module # # http://wiki.nginx.org/NginxHttpCoreModule # #---------------------------------------------------------------------- http { include /etc/nginx/mime.types; 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 /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; # # The default server # server { listen 80; server_name _; #charset koi8-r; #access_log logs/host.access.log main; location / { root /usr/share/nginx/html; index index.php index.html index.htm; } error_page 404 /404.html; location = /404.html { root /usr/share/nginx/html; } # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # Load config files from the /etc/nginx/conf.d directory include /etc/nginx/conf.d/*.conf; }
最终的问题是如何获取/pipe理(由mod_rewite /或NGinx Alternative驱动)显示为PHP文件,而不是一些文本或应用程序/八位字节stream。
顺便说一句我已经安装了PHP的FPM模块,所以PHP文件做渲染罚款..只是他们没有渲染时,由重写驱动。
非常感谢!
这里也是我的Nginx错误日志的全部。
2014/12/09 04:05:35 [error] 23378#0: *6796 open() "/usr/share/nginx/html/cgi-bin/authLogin.cgi" failed (2: No such file or directory), client: 210.3.228.123, server: vibeshed.com, request: "GET /cgi-bin/authLogin.cgi HTTP/1.1", host: "127.0.0.1" 2014/12/09 05:09:21 [error] 23378#0: *6810 open() "/usr/share/nginx/html/cgi-bin/authLogin.cgi" failed (2: No such file or directory), client: 84.61.245.6, server: vibeshed.com, request: "GET /cgi-bin/authLogin.cgi HTTP/1.1", host: "127.0.0.1" 2014/12/09 05:36:06 [error] 23378#0: *6813 open() "/usr/share/nginx/html/cgi-bin/authLogin.cgi" failed (2: No such file or directory), client: 178.193.100.96, server: vibeshed.com, request: "GET /cgi-bin/authLogin.cgi HTTP/1.1", host: "127.0.0.1" 2014/12/09 06:10:29 [error] 23378#0: *6815 open() "/usr/share/nginx/html/cgi-bin/authLogin.cgi" failed (2: No such file or directory), client: 88.175.95.10, server: vibeshed.com, request: "GET /cgi-bin/authLogin.cgi HTTP/1.1", host: "127.0.0.1" 2014/12/09 08:40:41 [error] 23378#0: *7270 open() "/usr/share/nginx/html/cgi-bin/authLogin.cgi" failed (2: No such file or directory), client: 14.136.83.67, server: vibeshed.com, request: "GET /cgi-bin/authLogin.cgi HTTP/1.1", host: "127.0.0.1" 2014/12/09 09:27:54 [error] 23378#0: *7284 open() "/usr/share/nginx/html/cgi-bin/authLogin.cgi" failed (2: No such file or directory), client: 118.163.106.140, server: vibeshed.com, request: "GET /cgi-bin/authLogin.cgi HTTP/1.1", host: "127.0.0.1" 2014/12/09 09:51:56 [error] 23379#0: *7454 open() "/usr/share/nginx/html/cgi-bin/authLogin.cgi" failed (2: No such file or directory), client: 59.127.84.8, server: vibeshed.com, request: "GET /cgi-bin/authLogin.cgi HTTP/1.1", host: "127.0.0.1" 2014/12/09 10:48:55 [error] 23379#0: *8009 open() "/usr/share/nginx/html/cgi-bin/authLogin.cgi" failed (2: No such file or directory), client: 88.159.106.164, server: vibeshed.com, request: "GET /cgi-bin/authLogin.cgi HTTP/1.1", host: "127.0.0.1" 2014/12/09 11:04:23 [error] 23379#0: *8102 open() "/usr/share/nginx/html/cgi-bin/authLogin.cgi" failed (2: No such file or directory), client: 95.89.236.195, server: vibeshed.com, request: "GET /cgi-bin/authLogin.cgi HTTP/1.1", host: "127.0.0.1" 2014/12/09 11:17:24 [error] 23379#0: *8103 open() "/usr/share/nginx/html/cgi-bin/authLogin.cgi" failed (2: No such file or directory), client: 80.219.188.234, server: vibeshed.com, request: "GET /cgi-bin/authLogin.cgi HTTP/1.1", host: "127.0.0.1" 2014/12/09 11:22:53 [error] 23379#0: *8104 open() "/usr/share/nginx/html/cgi-bin/authLogin.cgi" failed (2: No such file or directory), client: 203.186.126.186, server: vibeshed.com, request: "GET /cgi-bin/authLogin.cgi HTTP/1.1", host: "127.0.0.1" 2014/12/09 11:28:19 [error] 23379#0: *8105 open() "/usr/share/nginx/html/cgi-bin/authLogin.cgi" failed (2: No such file or directory), client: 212.41.105.10, server: vibeshed.com, request: "GET /cgi-bin/authLogin.cgi HTTP/1.1", host: "127.0.0.1" 2014/12/09 11:47:21 [error] 23379#0: *8108 open() "/usr/share/nginx/html/cgi-bin/authLogin.cgi" failed (2: No such file or directory), client: 60.249.117.137, server: vibeshed.com, request: "GET /cgi-bin/authLogin.cgi HTTP/1.1", host: "127.0.0.1" 2014/12/09 11:53:39 [error] 23379#0: *8109 open() "/usr/share/nginx/html/cgi-bin/authLogin.cgi" failed (2: No such file or directory), client: 77.41.149.118, server: vibeshed.com, request: "GET /cgi-bin/authLogin.cgi HTTP/1.1", host: "127.0.0.1" 2014/12/09 12:21:39 [error] 23379#0: *8110 open() "/usr/share/nginx/html/cgi-bin/authLogin.cgi" failed (2: No such file or directory), client: 24.226.239.76, server: vibeshed.com, request: "GET /cgi-bin/authLogin.cgi HTTP/1.1", host: "127.0.0.1" 2014/12/09 14:18:33 [error] 23382#0: *8162 open() "/usr/share/nginx/html/cgi-bin/authLogin.cgi" failed (2: No such file or directory), client: 61.197.228.249, server: vibeshed.com, request: "GET /cgi-bin/authLogin.cgi HTTP/1.1", host: "127.0.0.1" 2014/12/09 15:15:43 [error] 23379#0: *8708 open() "/usr/share/nginx/html/cgi-bin/authLogin.cgi" failed (2: No such file or directory), client: 61.224.19.150, server: vibeshed.com, request: "GET /cgi-bin/authLogin.cgi HTTP/1.1", host: "127.0.0.1" 2014/12/09 15:33:48 [error] 23379#0: *8887 open() "/usr/share/nginx/html/8080" failed (2: No such file or directory), client: 111.123.180.44, server: vibeshed.com, request: "GET /8080 HTTP/1.1", host: "115.230.125.165:61254" 2014/12/09 15:33:48 [error] 23379#0: *8888 open() "/usr/share/nginx/html/8080" failed (2: No such file or directory), client: 111.123.180.44, server: vibeshed.com, request: "GET /8080 HTTP/1.1", host: "115.230.125.165:61254" 2014/12/09 16:11:27 [error] 23381#0: *9215 open() "/usr/share/nginx/html/r/www/cache/static/home/img/logos/nuomi_ade5465d.png" failed (2: No such file or directory), client: 125.64.35.67, server: _, request: "GET http://s1.bdstatic.com/r/www/cache/static/home/img/logos/nuomi_ade5465d.png HTTP/1.1", host: "s1.bdstatic.com" 2014/12/09 16:22:33 [error] 23381#0: *9216 open() "/usr/share/nginx/html/cgi-bin/authLogin.cgi" failed (2: No such file or directory), client: 80.245.236.31, server: vibeshed.com, request: "GET /cgi-bin/authLogin.cgi HTTP/1.1", host: "127.0.0.1" 2014/12/09 16:57:52 [error] 23381#0: *9219 open() "/usr/share/nginx/html/cgi-bin/authLogin.cgi" failed (2: No such file or directory), client: 88.159.101.77, server: vibeshed.com, request: "GET /cgi-bin/authLogin.cgi HTTP/1.1", host: "127.0.0.1" 2014/12/09 17:12:39 [error] 23381#0: *9221 open() "/usr/share/nginx/html/r/www/cache/static/home/img/logos/nuomi_ade5465d.png" failed (2: No such file or directory), client: 125.64.35.67, server: vibeshed.com, request: "GET http://s1.bdstatic.com/r/www/cache/static/home/img/logos/nuomi_ade5465d.png HTTP/1.1", host: "s1.bdstatic.com" 2014/12/09 19:01:42 [error] 23379#0: *9235 open() "/usr/share/nginx/html/user/soapCaller.bs" failed (2: No such file or directory), client: 216.20.131.111, server: _, request: "GET /user/soapCaller.bs HTTP/1.1", host: "146.185.171.71" 2014/12/09 19:05:09 [error] 23379#0: *9236 open() "/usr/share/nginx/html/cgi-bin/authLogin.cgi" failed (2: No such file or directory), client: 46.107.209.83, server: vibeshed.com, request: "GET /cgi-bin/authLogin.cgi HTTP/1.1", host: "127.0.0.1" 2014/12/09 19:57:38 [error] 18171#0: *9 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 82.15.196.119, server: _, request: "GET /favicon.ico HTTP/1.1", host: "www.vibeshed.com" 2014/12/09 20:01:09 [error] 1445#0: *30 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 82.15.196.119, server: _, request: "GET /favicon.ico HTTP/1.1", host: "www.vibeshed.com" 2014/12/09 20:02:00 [error] 1445#0: *1 FastCGI sent in stderr: "PHP message: PHP Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0 Unable to open primary script: /usr/share/nginx/html/phpinfo.php (Permission denied)" while reading response header from upstream, client: 82.15.196.119, server: vibeshed.com, request: "GET /phpinfo.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "vibeshed.com" 2014/12/09 20:02:02 [error] 1445#0: *1 FastCGI sent in stderr: "PHP message: PHP Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0 Unable to open primary script: /usr/share/nginx/html/phpinfo.php (Permission denied)" while reading response header from upstream, client: 82.15.196.119, server: vibeshed.com, request: "GET /phpinfo.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "vibeshed.com" 2014/12/09 20:02:02 [error] 1445#0: *1 FastCGI sent in stderr: "PHP message: PHP Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0 Unable to open primary script: /usr/share/nginx/html/phpinfo.php (Permission denied)" while reading response header from upstream, client: 82.15.196.119, server: vibeshed.com, request: "GET /phpinfo.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "vibeshed.com" 2014/12/09 20:02:03 [error] 1445#0: *1 FastCGI sent in stderr: "PHP message: PHP Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0 Unable to open primary script: /usr/share/nginx/html/phpinfo.php (Permission denied)" while reading response header from upstream, client: 82.15.196.119, server: vibeshed.com, request: "GET /phpinfo.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "vibeshed.com" 2014/12/09 20:02:03 [error] 1445#0: *1 FastCGI sent in stderr: "PHP message: PHP Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0 Unable to open primary script: /usr/share/nginx/html/phpinfo.php (Permission denied)" while reading response header from upstream, client: 82.15.196.119, server: vibeshed.com, request: "GET /phpinfo.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "vibeshed.com" 2014/12/09 20:02:04 [error] 1445#0: *1 FastCGI sent in stderr: "PHP message: PHP Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0 Unable to open primary script: /usr/share/nginx/html/phpinfo.php (Permission denied)" while reading response header from upstream, client: 82.15.196.119, server: vibeshed.com, request: "GET /phpinfo.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "vibeshed.com" 2014/12/09 20:02:04 [error] 1445#0: *1 FastCGI sent in stderr: "PHP message: PHP Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0 Unable to open primary script: /usr/share/nginx/html/phpinfo.php (Permission denied)" while reading response header from upstream, client: 82.15.196.119, server: vibeshed.com, request: "GET /phpinfo.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "vibeshed.com" 2014/12/09 20:02:05 [error] 1445#0: *1 FastCGI sent in stderr: "PHP message: PHP Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0 Unable to open primary script: /usr/share/nginx/html/phpinfo.php (Permission denied)" while reading response header from upstream, client: 82.15.196.119, server: vibeshed.com, request: "GET /phpinfo.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "vibeshed.com" 2014/12/09 20:02:05 [error] 1445#0: *1 FastCGI sent in stderr: "PHP message: PHP Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0 Unable to open primary script: /usr/share/nginx/html/phpinfo.php (Permission denied)" while reading response header from upstream, client: 82.15.196.119, server: vibeshed.com, request: "GET /phpinfo.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "vibeshed.com" 2014/12/09 20:02:45 [error] 1445#0: *1 FastCGI sent in stderr: "PHP message: PHP Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0 Unable to open primary script: /usr/share/nginx/html/phpinfo.php (Permission denied)" while reading response header from upstream, client: 82.15.196.119, server: vibeshed.com, request: "GET /phpinfo.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "vibeshed.com" 2014/12/09 20:02:56 [error] 1445#0: *1 FastCGI sent in stderr: "PHP message: PHP Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0 Unable to open primary script: /usr/share/nginx/html/phpinfo.php (Permission denied)" while reading response header from upstream, client: 82.15.196.119, server: vibeshed.com, request: "GET /phpinfo.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "vibeshed.com" 2014/12/09 20:02:57 [error] 1445#0: *1 FastCGI sent in stderr: "PHP message: PHP Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0 Unable to open primary script: /usr/share/nginx/html/phpinfo.php (Permission denied)" while reading response header from upstream, client: 82.15.196.119, server: vibeshed.com, request: "GET /phpinfo.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "vibeshed.com" 2014/12/09 20:02:57 [error] 1445#0: *1 FastCGI sent in stderr: "PHP message: PHP Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0 Unable to open primary script: /usr/share/nginx/html/phpinfo.php (Permission denied)" while reading response header from upstream, client: 82.15.196.119, server: vibeshed.com, request: "GET /phpinfo.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "vibeshed.com" 2014/12/09 20:02:57 [error] 1445#0: *1 FastCGI sent in stderr: "PHP message: PHP Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0 Unable to open primary script: /usr/share/nginx/html/phpinfo.php (Permission denied)" while reading response header from upstream, client: 82.15.196.119, server: vibeshed.com, request: "GET /phpinfo.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "vibeshed.com" 2014/12/09 20:02:57 [error] 1445#0: *1 FastCGI sent in stderr: "PHP message: PHP Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0 Unable to open primary script: /usr/share/nginx/html/phpinfo.php (Permission denied)" while reading response header from upstream, client: 82.15.196.119, server: vibeshed.com, request: "GET /phpinfo.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "vibeshed.com"
这里的问题是,你使用了一个在线工具从Apache转换到nginx,并没有一个很好。
if (!-e $request_filename){ rewrite ^(.*)$ /index.php?/$0 break; }
这需要完全切割,并用try_filesreplace。
try_files $uri $uri/ /index.php?$uri;
你也放错了你的root指令。 它应该在server下,而不是在location下。