2017-10-14 132 views
1

我正在使用Linux Mint 18.2和docker。 目前我有2個來自bitnami的docker容器,1個是用於nginx的,另一個是php-fpm。 下面是nginx的我的搬運工,撰寫配置:訪問我的本地網站時爲什麼拒絕訪問權限?

version: '2' 

services: 
    nginx: 
    image: 'bitnami/nginx:latest' 
    group_add: 
     - www-data 
    restart: always 
    labels: 
     kompose.service.type: nodeport 
    ports: 
     - '80:8080' 
     - '443:8443' 
    volumes: 
     - 'nginx_data:/bitnami' 
     - ~/Documents/nginx/nginx.conf:/bitnami/nginx/conf/nginx.conf:ro 
     - ~/Documents/nginx/my_vhost.conf:/bitnami/nginx/conf/vhosts/my_vhost.conf:ro 
     - /usr/share/nginx/html:/app 

volumes: 
    nginx_data: 
    driver: local 

,這裏是爲PHP-FPM我的搬運工,compose.yml:

version: '2' 

services: 
    php: 
    tty: true # Enables debugging capabilities when attached to this container. 
    image: 'bitnami/php-fpm:latest' 
    labels: 
     kompose.service.type: nodeport 
    ports: 
     - 9000:9000 
    volumes: 
     - /usr/share/nginx/html:/app 
     - ~/Documents/nginx/nginx.conf:/bitnami/nginx/conf/nginx.conf:ro 
     - ~/Documents/nginx/my_vhost.conf:/bitnami/nginx/conf/vhosts/my_vhost.conf 

而且,這裏是我的nginx的配置:

server { 
    listen 0.0.0.0:8080; 
    server_name localhost; 
    root /app; 
    index index.htm index.html; 

    location /evodms {                                     
    # First attempt to serve request as file, then                             
    # as directory, then fall back to displaying a 404.                            
    # root /usr/share/nginx/html;                                  
    # root /var/www/html/evodms;                                  
    try_files $uri $uri/ /evodms/index.php?$args;                             
    } 

    location ~ \.php$ {                                     
    fastcgi_pass unix:/var/run/php/php5.6-fpm.sock;                          
    fastcgi_index index.php;                                
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;                      
    include  fastcgi_params;                               
    } 
} 

我已經啓動了所有容器和nginx容器生成的用戶1001,因此我將此用戶映射到www-data,FYI,我的evodms文件夾所有權已設置爲www-data。 但我收到此消息:

nginx_1 | 2017/10/14 06:12:39 [error] 25#0: *1 directory index of "/app/evodms/" is forbidden, client: 172.20.0.1, server: localhost, request: "GET /evodms/ HTTP/1.1", host: "localhost" 
nginx_1 | 172.20.0.1 - - [14/Oct/2017:06:12:39 +0000] "GET /evodms/ HTTP/1.1" 403 198 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36" 

任何線索?

+0

爲什麼你有兩個文件撰寫? – sauerburger

+0

我正在使用2個獨立的泊塢窗圖像 – budiantoip

回答

0

您的nginx嘗試在evodms文件夾中找到index.html。因爲您在根選項下將索引設置爲index index.htm index.html

我猜你的evodms存在於你的公共文件夾下嗎?

如果您設置了像這樣的位置路徑。

location /evodms {                                     
    try_files $uri $uri/ /evodms/index.php?$args;                             
} 

看看try_files。訂單是$ uri,然後是$ uri /。 nginx會檢查url/evodms /是否是一個文件夾?如果是,請將其退回。但如果不是,nginx會嘗試其他選項。

如何檢查。 首先,嘗試在evodms文件夾中添加文件index.html。它會顯示在你的頁面中,如果你訪問它,因爲nginx成功定義evodms爲文件夾。

或者只是從try_files拿出$uri/。所以nginx不會嘗試將evodms定義爲文件夾。它會直接重寫爲下一個選項。這是evodms/index.php?$args

0

/evodms從你的nginx配置中的位置,適用於所有的請求從/evodms啓動,因此,例如,當你請求/evodms/test,nginx的嘗​​試/app/evodms/test文件,然後再/app/evodms/test/文件夾,最後嘗試/app/evodms/index.php?$args

但是,當您請求/evodms/時,它會嘗試/app/evodms/,這是/的位置/evodms。在這種情況下,nginx會嘗試使用index選項中定義的索引文件。看起來你的/app/evodms文件夾中沒有index.htmlindex.htm,所以你得到403禁止錯誤。

爲了解決請求<your_domain>/evodms/,你應該添加index.php列出的索引文件:

index index.htm index.html index.php;