2016-02-27 76 views
0

這裏是我的問題加入域的Nginx配置

我有域「example.com」和我想的是域名與文件夾/var/www/html/example.com相關

我已經創建一個名爲 「example.com」 文件/ etc/nginx的/網站可用

server { 
    server_name http://example.com; 

    root /var/www/html/example.com; 
    index index.html index.php; 

    # set expiration of assets to MAX for caching 
    location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ { 
      expires max; 
      log_not_found off; 
    } 

    location/{ 
      # Check if a file or directory index file exists, else route it to index.php. 
      try_files $uri $uri/ /index.php; 
    } 

    location ~* \.php$ { 
      fastcgi_pass 127.0.0.1:9000; 
      include fastcgi.conf; 
    } 

這裏是我的默認放在/ etc/nginx的/啓用的站點 -

server { 
    listen 80 default_server; 
    listen [::]:80 default_server; 

    # SSL configuration 
    # 
    # listen 443 ssl default_server; 
    # listen [::]:443 ssl default_server; 
    # 
    # Self signed certs generated by the ssl-cert package 
    # Don't use them in a production server! 
    # 
    # include snippets/snakeoil.conf; 

    root /var/www/html; 

    # Add index.php to the list if you are using PHP 
    index index.php index.html index.htm index.nginx-debian.html; 

    server_name 188.226.145.195; 

    location/{ 
      # First attempt to serve request as file, then 
      # as directory, then fall back to displaying a 404. 
      try_files $uri $uri/ =404; 
    } 

    location /example.com/ { 
      try_files $uri $uri/ /example.com/index.php; 
    } 
文件

我知道問題出在根的/ var/www/html等,但不能化解它

錯誤日誌:

2016/02/27 13:53:53 [error] 10139#0: *11 directory index of "/var/www/html/" is forbidden, client: xxx.xx.xx.xx, server: 188.226.145.195, request: "GET/HTTP/1.1", host: "www.example.com" 

希望這是足夠的信息,以便some1可以提供幫助。 謝謝。

+0

'server_name'語法錯誤(見[這裏](HTTP:// nginx.org/en/docs/http/server_names.html))。另外,您是否已將新網站可用文件鏈接到啓用網站的目錄? –

+0

是的,它連接在sitest-enabled我修復了server_name,現在得到了新錯誤'2016/02/28 14:07:32 [error] 11045#0:* 317連接()失敗(111:連接被拒絕)到上游,客戶端:93.123.47.139,服務器:example.com,$ request:「GET/HTTP/1.1」,上游:「fastcgi://127.0.0.1:9000」,主機:「example.com」 ' – IdlleF

+0

新的錯誤意味着端口9000上的服務未運行。 –

回答

0

我做到了,問題是,我沒有給根默認位置,當我這樣做就像一個魅力:)