V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
yanwen
V2EX  ›  问与答

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

  •  
  •   yanwen · 2015-08-16 16:57:31 +08:00 · 3129 次点击
    这是一个创建于 3197 天前的主题,其中的信息可能已经有所发展或是发生改变。
    用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;
    }
    8 条回复    2015-09-01 09:39:13 +08:00
    ivmm
        1
    ivmm  
       2015-08-16 16:58:07 +08:00   ❤️ 1
    是404
    yanwen
        2
    yanwen  
    OP
       2015-08-16 16:59:16 +08:00
    @ivmm 是不是我nginx的配置错了呢??
    Mizzi
        3
    Mizzi  
       2015-08-16 17:24:11 +08:00   ❤️ 1
    用 orvice 的啊
    smileawei
        4
    smileawei  
       2015-08-16 18:15:47 +08:00 via iPhone   ❤️ 1
    后端用apache吧。
    yanwen
        5
    yanwen  
    OP
       2015-08-16 18:40:19 +08:00
    @Mizzi 求链接。。
    Mizzi
        6
    Mizzi  
       2015-08-16 20:33:51 +08:00   ❤️ 1
    ksupertu
        7
    ksupertu  
       2015-09-01 03:40:07 +08:00   ❤️ 1
    刚踩了一下坑,研究了下这个 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
        8
    yanwen  
    OP
       2015-09-01 09:39:13 +08:00
    @ksupertu

    非常感谢。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   982 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 22:19 · PVG 06:19 · LAX 15:19 · JFK 18:19
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.