2016-10-10 108 views
0

我有以下文件夾結構 文件夾/usr/share/nginx/html/myapp.com/Nginx的配置

-app 
-bootstrap 
-index.html 
-pages 
-rest 
--application 
---controllers 
----api 
----- Rest classes 
----- ..... 
--system 
--vendor 
--index.php 

這是我的nginx.conf

server { 
    listen  80; 
    server_name myapp.com; 

    root /usr/share/nginx/html/myapp.com; 

    index index.html index.htm index.php; 

    location/{ 
     root /usr/share/nginx/html/myapp.com; 
     try_files $uri/ $uri index.html =404; 
    } 

    location /rest/ { 
      alias /usr/share/nginx/html/myapp.com/rest/; 
      try_files $uri $uri/ index.php; 

      location ~ \.php$ { 
       fastcgi_split_path_info ^(.+\.php)(/.+)$; 
       fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; 
       fastcgi_index index.php; 
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
       include fastcgi_params; 
      } 
    } 

    location ~ \.php$ { 
     return 444; 
    } 
} 

nginx的訪問日誌

- - [10/Oct/2016:18:27:01 +0200] "GET /rest/api/users/sessionData HTTP/1.1" 444 0 "http://myapp.com/" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36" "-" 
- - [10/Oct/2016:18:27:01 +0200] "GET /rest/api/users/sessionData HTTP/1.1" 444 0 "http://myapp.com/" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36" "-" 

我一直在爲所有PHP請求獲取444錯誤。你能幫我正確設置我的nginx.conf。如果您需要任何其他信息,請讓我知道,我會提供。先謝謝你!

回答

0

這是我工作的解決方案

server { 
    listen  80; 
    server_name myapp.com; 

    root /usr/share/nginx/html/myapp.com; 

    index index.html index.htm index.php; 

    location/{ 
     root /usr/share/nginx/html/myapp.com; 
     try_files $uri/ $uri index.html =404; 
    } 

    location /rest/ { 
     alias /usr/share/nginx/html/myapp.com; 
     try_files $uri $uri/ /rest/index.php; 

     location ~ \.php$ { 
      fastcgi_split_path_info ^(.+\.php)(/.+)$; 
      fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; 
      fastcgi_index index.php; 
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
      include fastcgi_params; 
     } 
    } 

    location ~ \.php$ { 
     return 444; 
    } 
} 
0

請嘗試以下代碼,

http { 
    ... 
    map $request_uri $rot { 
     "~/rest" /usr/share/nginx/html/myapp.com/rest/; 
     default /usr/share/nginx/html/myapp.com/; 
    } 
    map $request_uri $ind { 
     "~/rest" index.php; 
     default index.html; 
    } 
    ... 
    server { 
     listen  80; 
     server_name myapp.com; 
     rewrite ^/rest(.*) $1 break; 
     root $rot; 

     index index.html index.htm index.php; 

     location/{ 
      try_files $uri/ $uri $ind =404; 
     } 

     location ~ \.php$ { 
      fastcgi_split_path_info ^(.+\.php)(/.+)$; 
      fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; 
      fastcgi_index index.php; 
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
      include fastcgi_params; 
     }   
    } 
    ... 
} 
+0

抱歉,但現在連角HTML是不可見... 404未找到 –

+0

能否請您檢查錯誤日誌? – Satys

+0

以及其空的:D 但訪問日誌看起來像這樣 - [11/Oct/2016:10:21:00 +0200]「GET/HTTP/1.1」404 571「 - 」「Mozilla/5.0(X11; Linux x86_64)AppleWebKit/537.36(KHTML,如Gecko)Chrome/53.0.2785.143 Safari/537.36「」 - 「 –