1. 程式人生 > >mac 上配置nginx過程中的問題記錄

mac 上配置nginx過程中的問題記錄

1、訪問專案程式碼的時候報出500錯誤,但是在檢視介面返回資料時,沒有什麼資訊,開啟nginx的日誌,顯示:

"GET / HTTP/1.1" 500 5 "-" "Mozilla/5.0 (這裡只擷取重要部分),搜的結果是許可權問題,專案用的是laravel框架,解決辦法是給storage/* directory and bootstrap/cache加上許可權,使用命令chmod -R 777 storage。參考來源如下圖:




2、favicon.ico 找不到:

解決辦法是在nginx的配置檔案的server中加上:

location = /favicon.ico {

            

log_not_found off;

}

3、還有一定要注意配置檔案中的檔案許可權和路徑問題,很多問題都是因為這引起的。

4、我nginx的配置的程式碼如下(nginx.conf):

user wyung  staff;

worker_processes  auto;


error_log  /usr/local/etc/nginx/logs/error.log;

#error_log  /usr/local/etc/nginx/logs/error.log notice;

error_log  /usr/local/etc/nginx/logs/error.log 

info;


#pid        logs/nginx.pid;



events {

    worker_connections  256;

}



http {

    include       mime.types;

    default_type  application/octet-stream;


    #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  logs/access.log main;


    sendfile        on;

    #tcp_nopush     on;


    #keepalive_timeout  0;

    keepalive_timeout  65;


    #gzip  on;


    server {

        listen       8080;

        server_name  localhost;


        #charset koi8-r;


        #access_log  logs/host.access.log main;

        location / {

            root   html;

            index  index.html index.htm 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;

        }

        location = /favicon.ico {

             log_not_found off;

        }

        # 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  $document_root$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;

        #}

    }


# another virtual host using mix of IP-, name-, and port-based configuration

    #

    #server {

    #    listen      8000;

    #    listen      somename:8080;

    #    server_name somename  alias  another.alias;


    #    location / {

    #        root   html;

    #        index index.html index.htm;

    #    }

    #}



    # HTTPS server

    #

    #server {

    #    listen      443 ssl;

    #    server_name localhost;


    #    ssl_certificate     cert.pem;

    #    ssl_certificate_key cert.key;


    #    ssl_session_cache   shared:SSL:1m;

    #    ssl_session_timeout 5m;


    #    ssl_ciphers HIGH:!aNULL:!MD5;

    #    ssl_prefer_server_ciphers on;


    #    location / {

    #        root   html;

    #        index index.html index.htm;

    #    }

    #}

    include servers/*;

}


5、servers資料夾中的一個子配置程式碼如下:

server {

     listen 10001;

     set $root_path '/Users/wyung/sdnm/sdnm_0.5/public';

     root $root_path;

     index index.php index.html index.htm;

     try_files $uri $uri/ @rewrite;

     location @rewrite {

     rewrite ^/(.*)$ /index.php?_url=/$1;

    }


    error_page 500 502 503 504 /50x.html;

    location = /50x.html {

        root /usr/share/nginx/html;

    }


     location ~ \.php($|/) {

      fastcgi_pass    127.0.0.1:9000;

      fastcgi_index   /index.php;

      include         fastcgi_params;

      fastcgi_split_path_info ^(.+\.php)(/.+)$;

      fastcgi_param   PATH_INFO  $fastcgi_path_info;

      #fastcgi_param   PATH_TRANSLATED $document_root$fastcgi_path_info;

          fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;

      }


      location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {

          root $root_path;

      }


      location ~/\.ht {

          deny all;

      }


      access_log /usr/local/etc/nginx/servers/access.log;

      error_log /usr/local/etc/nginx/servers/error.log;

 }