看板 Linux 關於我們 聯絡資訊
請問一下各位 我想讓php與rails並存於同一個網站上 並且使用path去區分網站 目前我有三個目錄分別是 /var/work/rails 存放rails的 /var/work/php 存放php程式 /var/work/nginx_root 存放404等錯誤的靜態網頁 目前我的設定檔為 worker_processes 1; events { worker_connections 1024; } http { passenger_root /usr/local/rvm/gems/ruby-2.1.2/gems/passenger-4.0.53; passenger_ruby /usr/local/rvm/gems/ruby-2.1.2/wrappers/ruby; include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; gzip on; server { rewrite_log on; error_log /opt/nginx/logs/error.log debug; listen 80; server_name localhost; root /var/work/nginx_root; error_page 403 404 405 406 500 501 502 503 504 /index.html; # for rails location /rails/assets { passenger_base_uri /rails/assets; passenger_enabled off; alias /var/work/rails/public/assets; } location /rails { alias /var/work/rails/public; passenger_base_uri /rails; passenger_app_root /var/work/rails; passenger_document_root /var/work/rails/public; passenger_enabled on; } } } 這個設定檔運作是正常的 rails與錯誤網頁的導向都可以正常運作 但我現在要加入php-fpm的設定 讓連入的網址如果是 http://192.168.1.1/php/test.php 會採用php執行請問該如何做 我加入了以以下的設定 location /php { alias /var/work/php; passenger_enabled off; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index test.php; fastcgi_param DOCUMENT_ROOT /var/work/php; fastcgi_param SCRIPT_FILENAME /var/work/php/$fastcgi_script_name; include fastcgi_params; } 但會得到錯誤 /var/work/nginx_root/test.php failed (2: No such file or directory) 也就是說他還是跑到 nginx_root 下面去了 請問我該如何做調整 以下是我使用的版本 nginx version: nginx/1.6.2 built by gcc 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) TLS SNI support enabled configure arguments: --prefix=/opt/nginx --with-http_ssl_module --with-http_gzip_static_module --with-http_stub_status_module --with-cc-opt=-Wno-error --add-module=/usr/local/rvm/gems/ruby-2.1.2/gems/passenger-4.0.55/ext/nginx -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 27.105.48.107 ※ 文章網址: https://www.ptt.cc/bbs/Linux/M.1427035575.A.AF5.html
justdoitmmo: php_fpm用proxy_pass去做吧,我沒記錯的話 03/23 00:17
justdoitmmo: php_fpm是啟動9000 port,導給本地9000就可以了 03/23 00:18
justdoitmmo: 抱歉我記錯,是fastcgi_pass沒錯,你沒設錯= = 03/23 00:21
bamchisu: 可以試著更改match條件為對於所有php檔pass到fastcgi: 03/25 18:36
bamchisu: 如下:location ~ .*.php$ { 03/25 18:37
bamchisu: fastcgi_pass 127.0.0.1:9000; 03/25 18:38
bamchisu: fastcgi_index index.php; 03/25 18:38
bamchisu: fastcgi_param SCRIPT_FILENAME $document_root$fastcg\ 03/25 18:39
bamchisu: i_script_name; 03/25 18:39
bamchisu: include fastcgi_params; } 03/25 18:39
bamchisu: 先看看php跑的對不對再來debug你的document_root設定 03/25 18:43
bamchisu: 另外一種可能的解法是設定link: 03/25 18:59
bamchisu: sudo ln -sv /var/work/php /var/work/nginx_root 03/25 18:59
bamchisu: ls -la /var/work/nginx_root/php 03/25 18:59
bamchisu: Access URL: http://localhost/php/test.php 03/25 19:00