nginx文件服务

  1. 文件服务。
  2. 反向代理。
Ubuntu

安装

sudo apt install nginx

配置

编辑配置文件/etc/nginx/sites-available/default

增加内容,其中root位置具体到项目可能有所不同。

location /images/ {
  root /home/milk/picture-html;
  autoindex on;
}
  • root:将images映射到/home/milk/picture-html路径。
  • autoindex:开启浏览功能。

重启 nginx

sudo systemctl restart nginx

可选

nginx 默认时间是UTC,修改为本地

编辑文件/etc/nginx/nginx.confhttp加入:

auto index_localtime on;
Gentoo

参考:https://wiki.gentoo.org/wiki/Nginx/en

安装

sudo emerge -av nginx

配置

mkdir /var/www/localhost/htdocs
echo 'Hello, world!' > /var/www/localhost/htdocs/index.html

网页访问http://localhost

反向代理

http {
  # ...
  server {
      listen 8091;
      server_name 127.0.0.1;
      location / {
          proxy_pass http://192.168.2.154:18000;
      }
  }
  # ...
}

访问本地,转发到服务器192.168.2.154


comment: