Как настроить Nginx для возврата CSV в качестве ответа? - PullRequest
0 голосов
/ 14 февраля 2019

У меня есть файл test.csv, расположенный в корне моей виртуальной машины, работающей в Ubuntu.Я использую Nginx в Laravel 4.2.

enter image description here

  • VM IP: 1.1.1.1
  • Домен: www.site.com

Как сделать этот CSV общедоступным через мой сайт: www.site.com/csv?

nginx

server {

    listen 80 default_server;
    server_name site.com www.site.com;
    root /home/forge/john/public;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    index index.html index.htm index.php;
    charset utf-8;

    location /nginx_status {
        stub_status on;
        access_log off;
        allow 127.0.0.1;
        deny all;
    }

    location /resume {
        #auth_basic "Restricted";
        #auth_basic_user_file /home/forge/john/.htpasswd;
        try_files $uri $uri/ /index.php?$query_string;
    }

    location /getIconBasedOnDevicesName {
        proxy_pass http://localhost:3030;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }

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

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;
    error_log  /var/log/nginx/default-error.log error;

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }

}

1 Ответ

0 голосов
/ 14 февраля 2019

Если файл расположен на /home/forge/john/public/test.csv, вы можете использовать:

location = /csv {
    try_files /test.csv =404;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...