nginx配置无效

时间:2015-05-23 02:06:11

标签: php nginx

server {
    listen       80;

    server_name  192.168.174.137;

    #charset koi8-r;

 #   access_log  logs/host.access.log  main;
    root /cgi;
    index index.html index.htm index.php;
   location / {
        try_files $uri $uri/ /index.php;
    }

    #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   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;
        include fastcgi.conf;
        fastcgi_pass   127.0.0.1:9000;
    }

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


fastcgi.conf

fastcgi_param  SCRIPT_FILENAME    $document_root$request_filename;
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  SCRIPT_NAME        $fastcgi_script_name;
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的:1.9.0
PHP:5.4.16
设置php-fpm听取127.0.0.1:9000

此配置通常适用于静态文件,例如http://192.168.174.137/1.html,但是当我尝试打开http://192.168.174.137/aaa.php时,它只会给我一个“找不到文件”的消息。 此外,当我在nginx配置中使用相对路径,例如root wwwroot html时,nginx可以使用/usr/local/nginx/前缀完成文件路径并正确执行php文件。 那么如何将webroot更改为除/usr/local/nginx以外的其他目录。

1 个答案:

答案 0 :(得分:0)

我只是通过设置selinux禁用来解决问题。