2016-08-22 68 views
2

我想在後端和angularjs在前端使用codeigniter網站。 對於後端,我使用nginx作爲服務器。 目前我遇到了正確配置nginx的問題。我想要實現的是將codeigniter和angularjs應用程序放在單獨的文件夾中。而我要的是訪問如下從my_website.com/apiNginx的子文件夾中的角和codeigniter應用程序

  • 從my_website.com

,並在文件夾的角度而言我希望讓他們在:

  • 笨:/無功/網絡/ HTML/API
  • 角:/無功/網絡/ HTML /角

到目前爲止,我已經設法使它在同一個文件夾中工作。所以現在我在/ var/www/html中添加了codeigniter,並且angular文件夾位於相同的目錄中。這樣我就可以從my_website.com/訪問codeigniter,並從my_website.com/app獲取角度,這不是我想要的。

我正在嘗試nginx/etc/nginx/sites-available/default文件的多個不同設置,但每次都遇到一些問題。我得到的最遠是將它們放在單獨的文件夾中,但codeigniter只能用於default_controller,我無法訪問任何其他文件。 這是當前的工作配置。

server { 
    listen 80; 
    listen [::]:80 default_server ipv6only=on; 

    root /var/www/html; 

    server_name localhost; 
    index index.php index.htm index.html; 

    location /app/ { 
     root /var/www/html/angular; 
     try_files $uri/ $uri index.html =404; 
    } 

    location/{ 
     try_files $uri $uri/ /index.php; 
     #index index.html; 
    } 

    error_page 404 /404.html; 

    error_page 500 502 503 504 /50x.html; 

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

這裏是簡單的配置,我只是嘗試從演示子文件夾笨運行,

server { 
     listen  80; 
     server_name localhost; 
     root /var/www/html; 
     autoindex on; 
     index index.php; 

     location/{ 

      #try_files $uri $uri/ /index.php; 
       try_files $uri $uri/ /index.php$request_uri; 
      location = /demo/index.php { 
       try_files $uri $uri/ /index.php$request_uri; 
       fastcgi_split_path_info ^(.+\.php)(/.+)$; 
       fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; 

       fastcgi_param SCRIPT_FILENAME /var/www/html/demo$fastcgi_script_name; 
       include  fastcgi_params; 
      } 
     } 

     location ~ \.php$ { 
      return 444; 
     } 


} 

這裏my_website.com/demo/index.php工作正常,但my_website.com/ demo/index.php/welcome shows 500內部服務器錯誤

我希望自己清楚。 我嘗試了很多不同的在線配置,但我總是遇到一些麻煩。你們能爲你們提出一些簡單的解決方案嗎?

感謝, Mateusz

+0

你的日誌裏有什麼錯誤? –

+0

我在哪裏可以查看該日誌? – Mateusz

+0

默認情況下它應該位於'/ var/log/nginx/* .log'下,您還可以設置[error_log](http://nginx.org/en/docs/ngx_core_module.html?&_ga=1.179635491.686758843.1471931560# error_log)指令重定向到特定文件 –

回答

1

我終於設法使其工作就是我想要的。我已經使用這個解決方案link使它在子目錄中的codeigniter中工作,這是主要問題。下面是我的配置:

server { 
    listen  80; 
    server_name localhost; 
    root /var/www/html; 
    autoindex on; 
    index index.html; 

    location/{ 
     root /var/www/html/angular; 
     try_files $uri/ $uri index.html =404; 
    } 

    location /api/ { 
      alias /var/www/html/api/; 
      try_files $uri $uri/ /api/index.php; 

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

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

感謝@FrédéricHenri使用/var/log/nginx/*.log下的日誌文件表明,與跟蹤nginx的重定向請求的方式幫助。此外,我遇到的情況是,網頁瀏覽器緩存網站(我認爲這是發生了什麼),所以當我對配置文件進行一些更改時,給了我錯誤的結果。

相關問題