2012-06-16 528 views
22

我剛剛在一個小時前安裝了nginx和php fastcgi,在閱讀快速啓動配置和nginx文檔等示例後,我無法使其正常工作。正確配置nginx到localhost?

無論我改變或嘗試,我總是隻得到「歡迎使用Nginx!」屏幕在 「localhost/...」 - 我不能甚至稱之爲一個簡單的index.html

我的配置:

(註釋中的東西是什麼,我嘗試了)

// default nginx stuff (unchanged) 

server { 
    #listen 80 default_server; 
    #listen 80 default; 
    listen 80; 

    #server_name localhost; 
    #server_name _; 

    #access_log /var/log/nginx/board.access_log; 
    #error_log /var/log/nginx/board.error_log; 

    #root /var/www/board; 
    #root /var/www/board/public/; 
    root /var/www/board/public; 

    #index index.html; 
    index index.html index.htm index.php; 
} 

如果我理解它是正確的,這應該是最簡單的設置,對吧?只是定義listen 80;index index.html;但我只是不能得到它的工作

文件/var/www/board/public/index.html存在,之前我浪費了2個小時嘗試一些有內容

,可以你的某個人快速觀察並告訴我我做錯了什麼?謝謝。

回答

25

基本上你沒有聲明nginx用來綁定URL和資源的位置。

server { 
      listen  80; 
      server_name localhost; 

      access_log logs/localhost.access.log main; 

      location/{ 
       root /var/www/board/public; 
       index index.html index.htm index.php; 
      } 
     } 
+0

嗯,我有 - 我說,哪裏是什麼我嘗試了「評論」線 - 所以服務器名本地主機已經嘗試過 - 但我會再試您的設置,給我一分鐘 – Katai

+0

@Katai注意'位置/ {'這是主要問題... –

+0

是的,我沒有'位置/ {}'裏面的'root'和'index',因爲http://wiki.nginx.org/Pitfalls – Katai