网站首页 > 技术教程 正文
1、下载
下载Nginx软件,进行解压。
2、配置nginx.conf
下面需要修改nginx.conf来实现直接使用http://localhost/upload/1.jpg访问服务器的图片的功能(这里本地就是服务器)。
目前我已知的nginx支持的有两种:1、配置root,2、配置alias
本地测试的图片放在nginx目录的html文件夹下面
第一种:
root:会网访问url后面拼接配置的路径
配置实例如下:
location /images/ {
root html;
index index.html index.htm;
}
对于这种配置,直接访问http://localhost/images/1.jpg即可访问到images文件夹下的图片。
(访问路径会被指向http://localhost/html/images/1.jpg)
第二种:
alias:直接指向目标文件的物理地址。
配置实例如下:
location /upload/ {
alias E:/ljdworkspace/nginx-1.12.2/nginx-1.12.2/html/images/;
autoindex on;
}
对于这种配置,直接访问http://localhost/upload/1.jpg 即可访问到E盘指定目录下的images文件夹里的图片。
————————————————
参照如下:使用第一种方式root配置
#user nobody;
worker_processes 1; #nginx开启的进程数,一般为cpu内核的整数倍
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
#指定最大可以同时接收的连接数量,这里一定要注意,最大连接数量是和worker processes共同决定的。
#multi_accept on;配置指定nginx在收到一个新连接通知后尽可能多的接受更多的连接
#use epoll;配置指定了线程轮询的方法,如果是linux2.6+,使用epoll,如果是BSD如Mac请使用Kqueue
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;#配置on让sendfile发挥作用,将文件的回写过程交给数据缓冲去去完成,而不是放在应用中完成,这样的话在性能提升有有好处
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 8090; #配置端口
server_name images.shinelon.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location /images/ {
root C:\images;
index index.html index.htm;
}
location /imgs/ {
root C:\imgs;
index index.html index.htm;
}
location /imgs2/ {
root C:\images2;
index index.html index.htm;
}
# 上面配置了三个文件夹,在同一个nginx中,根据images、imgs、imgs2可以访问各自下面的图片信息
#这样就可以配置多盘访问,如对D、E、F盘或者内网挂载的网盘进行访问。
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
2021年5月7日 记。
猜你喜欢
- 2024-10-14 深入浅出Nginx,如何做到高并发下的高效处理?如何做到热部署?
- 2024-10-14 「Docker类」 使用Dockerfile构建并部署nginx
- 2024-10-14 你所熟悉的nginx还可以用docker这样部署~
- 2024-10-02 如何使用Terraform部署NGINX容器(terraform构建与运行)
- 2024-10-02 Nginx基础、部署、配置(nginx简单配置)
- 2024-10-02 nginx安装部署和配置管理(nginx1.16安装)
- 2024-10-02 小白爱折腾·其五:如何在Nginx下部署项目文件夹
- 2024-10-02 nginx的完全离线部署教程,涨知识了
你 发表评论:
欢迎- 08-06linux 和 windows文件格式互相转换
- 08-06谷歌 ChromeOS 已支持 7z、iso、tar 文件格式
- 08-06Linux下比较文件内容的6种方法
- 08-06文件格式及功能汇总
- 08-0610个Linux文件内容查看命令的实用示例
- 08-06Linux-如何区分不同文件类型
- 08-06Zabbix技术分享——监控windows进程资源使用情况
- 08-06Linux系统卡顿?学会ps命令这三招,轻松定位问题进程
- 最近发表
- 标签列表
-
- 下划线是什么 (87)
- 精美网站 (58)
- qq登录界面 (90)
- nginx 命令 (82)
- nginx .http (73)
- nginx lua (70)
- nginx 重定向 (68)
- Nginx超时 (65)
- nginx 监控 (57)
- odbc (59)
- rar密码破解工具 (62)
- annotation (71)
- 红黑树 (57)
- 智力题 (62)
- php空间申请 (61)
- 按键精灵 注册码 (69)
- 软件测试报告 (59)
- ntcreatefile (64)
- 闪动文字 (56)
- guid (66)
- abap (63)
- mpeg 2 (65)
- column (63)
- dreamweaver教程 (57)
- excel行列转换 (56)
本文暂时没有评论,来添加一个吧(●'◡'●)