2017-04-14 86 views
0

我目前正在空閒時間在一個小型網站上工作。對於開發,我將所有的git倉庫保存在〜/ git中。是否可以配置nginx,以便如果我去localhost/A或localhost/B,它會分別使用〜/ git/A和〜/ git/B?NGinx:將localhost/project設置爲項目git文件夾

我使用的Fedora和一個單一的回購試過,但我不斷收到404:

/etc/nginx/nginx.conf

user nginx; 
worker_processes auto; 
error_log /var/log/nginx/error.log; 
pid /run/nginx.pid; 

events { 
    worker_connections 1024; 
} 

http { 
    log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 
         '$status $body_bytes_sent "$http_referer" ' 
         '"$http_user_agent" "$http_x_forwarded_for"'; 

    access_log /var/log/nginx/access.log main; 

    sendfile   on; 
    tcp_nopush   on; 
    tcp_nodelay   on; 
    keepalive_timeout 65; 
    types_hash_max_size 2048; 

    include    /etc/nginx/mime.types; 
    default_type  application/octet-stream; 

    server { 
     listen  80; 
     server_name localhost; 
     root   /home/MartenBE/git/; 
     index  index.html index.php; 

     location /A/ { 
      alias /home/MartenBE/git/A/; 
     } 
    } 

    server { 
     listen  80 default_server; 
     listen  [::]:80 default_server; 
     server_name _; 
     root   /usr/share/nginx/html; 

     # Load configuration files for the default server block. 
     include /etc/nginx/default.d/*.conf; 

     location/{ 
     } 

     error_page 404 /404.html; 
      location = /40x.html { 
     } 

     error_page 500 502 503 504 /50x.html; 
      location = /50x.html { 
     } 
    } 
} 

回答

0

我認爲只有以下應爲你工作。

server { 
    listen  80; 
    server_name localhost; 
    root   /home/MartenBE/git/; 
    index  index.html index.php; 
} 

你並不需要添加location模塊,因爲您已經定義root。現在,如果您嘗試使用localhost/A/index.html,Nginx會嘗試在/home/MartenBE/git/A/index.html下找到它。

您正在嘗試的請求是什麼?

+0

我只是想通過沖浪爲「localhost/A」在我的網頁瀏覽器去的網頁。錯誤日誌給出以下內容: > 2017/04/14 12:10:47 [error] 6046#0:* 1 open()「/ usr/share/nginx/html/A」失敗(2:沒有這樣的文件或目錄),客戶端:: 1,服務器:_,請求:「GET/A HTTP/1.1」,主機:「本地主機」 – MartenBE

+0

得到了問題,刪除默認服務器塊(第二個) –

0

首先,從主要的nginx conf文件中分離出站點配置是很好的。
執行以下操作..

  • /etc/nginx/nginx.conf刪除所有server塊。
  • 使用以下內容在/etc/nginx/sites-available/yourconf中創建一個文件。

    server { listen 80; server_name localhost; root /home/MartenBE/git/; index index.html index.php; }

  • /etc/nginx/sites-enabled/yourconf創建一個符號鏈接配置文件。

  • 刪除/etc/nginx/sites-enabled/default &重新加載nginx配置。

注:如果您使用的是Ubuntu的運行sudo service nginx reload

相關問題