帮我看看一个 moess 搭建起来的网站?金币感谢。。

2015-08-16 16:57:31 +08:00
 yanwen
用lnmp 1.2搭建好之后,配置按要求配好。。然后有个奇怪的问题:

首页打开貌似正常

http://ss.iwant.pw/

其他页面404 了。

请问这是为什么呢??

nginx的配置文件如下:

server
{
listen 80;
#listen [::]:80;
server_name ss.iwant.pw;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/ss.iwant.pw;

location / {
rewrite ^/(welcome(/index)?|index(\.php)?)/?$ / redirect;
rewrite ^/(.*)/index/?$ /$1 redirect;
if (!-e $request_filename){
rewrite ^/(.+)/$ /$1 redirect;
}
rewrite ^system.* /index.php/$1 break;
if (!-e $request_filename){
rewrite ^/(.*)$ /index.php/$1 break;
}
}
#error_page 404 /404.html;
location ~ [^/]\.php(/|$)
{
# comment try_files $uri =404; to enable pathinfo
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
#include pathinfo.conf;
}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}

location ~ .*\.(js|css)?$
{
expires 12h;
}

access_log off;
}
3133 次点击
所在节点    问与答
8 条回复
ivmm
2015-08-16 16:58:07 +08:00
是404
yanwen
2015-08-16 16:59:16 +08:00
@ivmm 是不是我nginx的配置错了呢??
Mizzi
2015-08-16 17:24:11 +08:00
用 orvice 的啊
smileawei
2015-08-16 18:15:47 +08:00
后端用apache吧。
yanwen
2015-08-16 18:40:19 +08:00
@Mizzi 求链接。。
Mizzi
2015-08-16 20:33:51 +08:00
ksupertu
2015-09-01 03:40:07 +08:00
刚踩了一下坑,研究了下这个 moess 配置 nginx 的关键在于开启 nginx 的 pathinfo 支持,不然的话弹一堆 404 ,需要注意的地方是:
1 、添加重定向
```
location / {
if (!-e $request_filename ) {
rewrite ^/(.*)$ /index.php/$1 last;
break;
}
}
```
2 、 fastcgi 配置
```
location ~ \.php {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi_pathinfo.conf;

include fastcgi_params;
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+?\.php )(/.+)$") {
set $real_script_name $1;
set $path_info $2;
}

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
}
```
注意此处的\.php 后面的$符号要删去,切记如此
3 、 fcgi_pathinfo.conf 的内容
```
#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fastcgi_param SCRIPT_NAME $fastcgi_script_name; #这两行是需要注释掉的,请注意
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;

fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param HTTPS $https if_not_empty;

fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;

fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
```
然后 nginx -t 测试一下, nginx -s reload 重新读取配置文件后大功告成,写在这里给以后踩坑的同学们看一下
yanwen
2015-09-01 09:39:13 +08:00
@ksupertu

非常感谢。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/213561

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX