【问题标题】:opensuse (tumbleweed) + nginx + codeigniter 404 issueopensuse (tumbleweed) + nginx + codeigniter 404 问题
【发布时间】:2016-09-14 07:20:35
【问题描述】:

我已经为此奋斗了一段时间,但仍然无法让它运行。我让 nginx 在带有 codeigniter 应用程序的 opensuse tumbleweed 上运行。

我毫无问题地进入首页,但任何打开控制器的尝试都失败并出现 404 错误。

当我在 Ubuntu 上工作时,我可以通过一些谷歌搜索在几分钟内解决这个问题,但由于某种原因我在这里很挣扎。我正在为 nginx 附加我的默认配置文件。一定有一些我真的没有在这里看到的东西,因为我过去有这个工作。 opensuse 上的 nginx 真的那么痛苦吗?

server {
    listen       80;
    server_name  localhost;
    root /usr/share/nginx/html/;
    index index.php;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
        root   /usr/share/nginx/html/;
        index  index.php index.html index.htm;

        ## Handling of CORS
        if ($request_method = 'OPTIONS') {
            add_header 'Access-Control-Allow-Origin' '*';
        #
        # Om nom nom cookies
        #
            add_header 'Access-Control-Allow-Credentials' 'true';
            add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
        #
        # Custom headers and headers various browsers *should* be OK with but aren't
        #
            add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
        #
        # Tell client that this pre-flight info is valid for 20 days
        #
            add_header 'Access-Control-Max-Age' 1728000;
            add_header 'Content-Type' 'text/plain charset=UTF-8';
            add_header 'Content-Length' 0;
            return 204;
        }
        if ($request_method = 'POST') {
            add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Allow-Credentials' 'true';
            add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
            add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
        }
        if ($request_method = 'GET') {
            add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Allow-Credentials' 'true';
            add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
            add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
        }
    }

    #error_page  404              /404.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$ {

        try_files $uri =404;
        fastcgi_pass    127.0.0.1:9000;
        fastcgi_index   index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        #fastcgi_ignore_client_abort off;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
        deny  all;
    }
}

【问题讨论】:

    标签: codeigniter nginx opensuse


    【解决方案1】:

    是的,我最终找到并回答了这个问题。我几乎完全删除了配置文件的内容,并用我在 nginx 网站 (here) 上找到的内容替换了它们。

    有趣的是,如果您注意到配置文件中没有更多用于处理 CORS 的指令,但所有内容(如字体、脚本等)都可以正常工作,而不会在 localhost 上出现故障。

    server {
        listen       80;
        server_name  localhost;
        root /usr/share/nginx/html;
        autoindex on;
        index index.php;
    
        location / {
    
                try_files $uri $uri/ /index.php;
    
                location = /index.php {
    
                    fastcgi_pass   127.0.0.1:9000;
                    fastcgi_param  SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
                    include        fastcgi_params;
                }
            }
    
            location ~ \.php$ {
                return 444;
            }
    
    }
    

    希望对某人有用;)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-25
      • 2016-06-10
      • 1970-01-01
      • 2016-06-23
      • 1970-01-01
      • 2016-07-13
      相关资源
      最近更新 更多