2016-10-10 3 views
0

У меня есть следующая структура папок в папке /usr/share/nginx/html/myapp.com/конфигурации Nginx для угловых и CodeIgniter в подпапке

-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" "-" 

Я все время получаю 444 ошибки для всех запросов php. Не могли бы вы помочь мне правильно установить 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 Not Found –

+0

Можете ли вы проверить журнал ошибок? – Satys

+0

ну его пустой: D , но журналы доступа выглядят так: - - [11/окт./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 "" - –

Смежные вопросы