nginx配置访问图片路径以及html静态页面的调取方法_nginx

给大家讲一个快速配置nginx访问图片地址,以及访问html静态页面的配置。

1.实验环境

首先随便某个路径下创建相应的目录。如图下

2.在里面放自定义的html或者图片。

3.nginx配置

user root;
worker_processes 1;  

#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;
}  

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;
  #tcp_nopush   on;  

  #keepalive_timeout 0;
  keepalive_timeout 65;  

  #gzip on;  

  server {
    listen    80;#端口号
    server_name localhost;#本机  

    charset utf-8;  

    #access_log logs/host.access.log main;  

  location ~ .*\.(gif|jpg|jpeg|png)$ {
    expires 24h;
      root /home/images/;#指定图片存放路径
      access_log /usr/local/websrv/nginx-1.9.4/logs/images.log;#日志存放路径
      proxy_store on;
      proxy_store_access user:rw group:rw all:rw;
      proxy_temp_path     /home/images/;#图片访问路径
      proxy_redirect     off;
      proxy_set_header    Host 127.0.0.1;
      client_max_body_size  10m;
      client_body_buffer_size 1280k;
      proxy_connect_timeout  900;
      proxy_send_timeout   900;
      proxy_read_timeout   900;
      proxy_buffer_size    40k;
      proxy_buffers      40 320k;
      proxy_busy_buffers_size 640k;
      proxy_temp_file_write_size 640k;
      if ( !-e $request_filename)
      {
         proxy_pass http://127.0.0.1;#默认80端口
      }
  }   

    location / {
      root  /home/html; #html访问路径
      index index.html index2.htm; #html文件名称 

    } 

    error_page 404       /404.html; </span> 

4.查看编译是否有出错,如果没出错则设置成功。

5.访问nginx则能访问到访问的图片地址。

6.访问自定义html时。

成功。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索nginx
, nginx访问静态资源
, 访问静态页面
访问静态html
nginx访问静态文件、nginx访问静态资源、nginx访问静态资源404、nginx访问静态图片、nginx 访问静态页面,以便于您获取更多的相关知识。

时间: 2024-09-19 09:00:26

nginx配置访问图片路径以及html静态页面的调取方法_nginx的相关文章

Nginx配置编写时支持逻辑运算与大小写字母转换的方法_nginx

逻辑运算nginx的配置中不支持if条件的逻辑与&& 逻辑或|| 运算 ,而且不支持if的嵌套语法,否则会报下面的错误:nginx: [emerg] invalid condition. 我们可以用变量的方式来间接实现. 要实现的语句: if ($arg_unitid = 42012 && $uri ~/thumb/){ echo "www.jb51.net"; } 如果按照这样来配置,就会报nginx: [emerg] invalid conditio

帝国CMS不同会员组查看文章权限判断在静态页面的实现方法

帝国CMS不同会员组查看文章权限判断在静态页面的实现方法 <?php require("class/connect.php"); include("class/db_sql.php"); include("class/config/config.php"); include("data/dbcache/class.php"); $link=db_connect(); $empire=new mysqlquery(); $

Nginx配置的rewrite编写时last与break的区别分析_nginx

在使用nginx配置rewrite中经常会遇到有的地方用last并不能工作,换成break就可以,其中的原理是对于根目录的理解有所区别,按我的测试结果大致是这样的. location / { proxy_pass http://test; alias /home/html/; root /home/html; rewrite "^/a/(.*)\.html$" /1.html last; } 在location / { 配置里: 1.使用root指定源:使用last和break都可以

Nginx配置PHP的Yii与CakePHP框架的rewrite规则示例_nginx

Yii的Nginx rewrite 如下为nginx yii的重写 server { set $host_path "/data/site/www.jb51.net"; access_log /data/logs/nginx/www.jb51.net_access.log main; server_name jb51.net www.jb51.net; root $host_path/htdocs; set $yii_bootstrap "index.php"; #

让Apache支持Rewrite静态页面重写的方法_Linux

首先确定您使用的 Apache 版本,及是否加载了 mod_rewrite 模块. Apache 1.x 的用户请检查 conf/httpd.conf 中是否存在如下两段代码: LoadModule rewrite_module libexec/mod_rewrite.so AddModule mod_rewrite.c Apache 2.x 的用户请检查 conf/httpd.conf 中是否存在如下一段代码: LoadModule rewrite_module modules/mod_rew

Asp.Net生成静态页面的实现方法_实用技巧

复制代码 代码如下: using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using Syste

nginx提示502 页面的解决方法_nginx

例如: 复制代码 代码如下:     http      {      ......      fastcgi_connect_timeout 300;      fastcgi_send_timeout 300;      fastcgi_read_timeout 300;      ......      }    也有可能是PHP代码不正确,比如SVN冲突等原因.

网站生成静态页面攻略

攻略|静态|页面 生成HTML方法主要步骤只有两个: 一.获取要生成的html文件的内容二.将获取的html文件内容保存为html文件 我在这里主要说明的只是第一步:如何获取要生成的html文件的内容: 目前常用获取html文件的内容的方法有几下几种: 1.这种方法与是在脚本内写要生成的html内容,不太方便预览生成页面的内容,无法可视化布局页面,更改html模板时会更加复杂.用这种方法的人很多,但我感觉这种方法是最不方便的. str="<html标记>内容</html标记&g

网站生成静态页面攻略 -- 生成静态页面的方法

攻略|静态|页面 生成HTML方法主要步骤只有两个: 一.获取要生成的html文件的内容二.将获取的html文件内容保存为html文件 我在这里主要说明的只是第一步:如何获取要生成的html文件的内容: 目前常用获取html文件的内容的方法有几下几种: 1.这种方法与是在脚本内写要生成的html内容,不太方便预览生成页面的内容,无法可视化布局页面,更改html模板时会更加复杂.用这种方法的人很多,但我感觉这种方法是最不方便的. str="<html标记>内容</html标记&g