【问题标题】:How to configure Nginx to return a CSV as response?如何配置 Nginx 以返回 CSV 作为响应?
【发布时间】:2019-02-14 06:58:51
【问题描述】:

我有一个test.csv 文件,位于运行在 Ubuntu 上的 VM 的根目录中。 我在Laravel 4.2 中使用Nginx

  • 虚拟机IP:1.1.1.1
  • 域名:www.site.com

如何通过我的网站:www.site.com/csv 公开访问该 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;
    }

}

【问题讨论】:

标签: php laravel csv ubuntu nginx


【解决方案1】:

如果文件位于/home/forge/john/public/test.csv,您可以使用:

location = /csv {
    try_files /test.csv =404;
}

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-11-21
  • 1970-01-01
  • 1970-01-01
  • 2018-01-19
  • 1970-01-01
  • 1970-01-01
  • 2016-02-25
相关资源
最近更新 更多