2015-04-07 126 views
0

我對配置nginx服務器有一點經驗,這是我的麻煩。 我想設置正確的位置。我有兩個方向:address.comaddress.com/api兩個方向的Nginx位置配置

對於最後的方向(API)我已設置位置,它工作正常。 API位於/var/www/project/api文件夾中。

root /var/www/project; 
index index.php; 
server_name localhost; 

location /api { 
      try_files /api/$uri $uri/ /api/index.php?$query_string; 
      fastcgi_pass 127.0.0.1:9000;     
      fastcgi_split_path_info ^/api/(.+\.php)(/.+)$; 
      fastcgi_intercept_errors on; 
      fastcgi_index index.php; 
      include fastcgi_params; 
} 
location ~ \.php$ { 
      try_files $uri =404; 
      fastcgi_keep_conn on; 
      fastcgi_pass 127.0.0.1:9000; 
      fastcgi_index index.php; 
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
      include  fastcgi_params; 
      fastcgi_buffer_size 32k; 
      fastcgi_busy_buffers_size 64k; 
      fastcgi_buffers 4 32k; 
      fastcgi_split_path_info ^(.+\.php)(/.+)$; 
    } 

現在我需要執行根address.com到在/ var/WWW /項目/網站。在這裏我有一些麻煩。

第一件事,我做什麼我就寫了:

location/{ 
     alias /var/www/project/website/; 
} 

然後我試圖添加許多不同的變體,這裏是我的最後一個音符。

我已經把它裏面位置/ {}

 location ~ ^/(.+\.php)$ { 
      alias /var/www/project/website/; 
      include /etc/nginx/fastcgi.conf; 
      proxy_intercept_errors on; 
      fastcgi_split_path_info ^(.+\.php)(.*)$; 
      fastcgi_intercept_errors on; 
      fastcgi_pass 127.0.0.1:9000; 
      fastcgi_index index.php; 
    } 

/etc/nginx/fastcgi.conf文件我已經加入

fastcgi_param PATH_TRANSLATED $document_root$fastcgi_script_name; 

而且我得到的所有時間403 Forbidden404未找到或在nginx錯誤中記錄日誌,例如,/var/www/project/website/...找不到

有人有與nginx配置的經驗,可以告訴,如何設置/網站位置正確?

回答

0

類似的東西:

server { 
    listen 80; 
    server_name localhost; 

    root /var/www/src/website; 
    index index.php index.html; 

    error_log /var/log/nginx/error.log; 

    location/{ 
     try_files $uri $uri/ =404; 
    } 
    location /test { 
     try_files $uri $uri/test.html =404; 
    } 
    location /api/ { 
     alias /var/www/src/api/; 
     try_files $uri $uri/ /index.php =404; 
     fastcgi_pass unix:/var/run/php5-fpm.sock; 
     fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     include /etc/nginx/fastcgi_params; 
    } 
    location /pmants { 
     root /var/www/src/; 
     index index.php index.html index.htm; 
     location ~ ^/pmants/(.+\.php)$ { 
       try_files $uri =404; 
       root /var/www/src/; 
       fastcgi_pass unix:/var/run/php5-fpm.sock; 
       fastcgi_index index.php; 
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
       include /etc/nginx/fastcgi_params; 
     } 

     location ~* ^/pmants/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ { 
       root /var/www/src/; 
     } 
    } 
    location ~* \.php { 
     include fastcgi_params; 

     fastcgi_pass unix:/var/run/php5-fpm.sock; 

     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     fastcgi_cache off; 
     fastcgi_index index.php; 
    } 
}