首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Nginx搭建并且访问图片

Nginx搭建并且访问图片

作者头像
DataScience
发布2020-05-07 18:17:43
7.3K0
发布2020-05-07 18:17:43
举报
文章被收录于专栏:A2DataA2Data

Nginx

Nginx (engine x) 是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器。Nginx是由伊戈尔·赛索耶夫为俄罗斯访问量第二的Rambler.ru站点开发的。

1、Nginx中文网

中文官网地址:https://www.nginx.cn/doc/

2、 安装

1、yum 安装 或者下载安装包

yum install -y wget && wget -O install.sh http://download.bt.cn/install/install_6.0.sh && bash install.sh

1.1 也可以下下载安装包
http://nginx.org/en/download.html

上传到服务器位置:
/usr/local

2. 解压到nginx目录下
tar xf nginx-1.9.9.tar.gz

cd nginx-1.9.9

3. 运行
./configure --prefix=/usr/local/nginx

4. 编译
make
make install

5. 启动

cd ../nginx

./sbin/nginx

6. kill 

netstat -ntlp | grep nginx

ps -ef | grep nginx

kill -9  10581  --- 端口号

3、部署静态图片

1.修改配置文件

# 1. 首先修改nginx的配置文件 nginx/conf/nginx.conf
# 2. 将user nobady 改成 user root (原来得注释掉即可)
---- 这里得意思是 root权限访问文件 配置文件如下----
#user  nobody;
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; # 开启gzip
    gzip_disable "msie6"; #IE6 不适用gzip
    gzip_vary on; # 设置为on 会在Header里增加 ”Vary:Accept-Encodng“
    gzip_proxied any:# 代理数据结果得压缩
    gzip_comp_level 6; # gzip压缩比( 1-9 ),越小压缩效果越差,但是越大处理效果越慢,所以一般取中间值
    gzip_buffers 18 8k; # 获取多少内存用于缓存压缩结果
    gzip_http_version 1.1; # 识别http协议版本
    gzip_min_length 1k; #设置允许压缩得页面最小字节数,超过1k得文件会被压缩
    gzip_types application/javascipt text/css; # 对特定得MIME类型生效,js和css文件会被压缩

    include /usr/local/nginx/vhosts/*;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }





        location /images/ {
            root   /ui/;
            autoindex on;
        }




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

}

3.nginx指向地址

上边已经有了,拿出来看明显一点。

        location /images/ {
            root   /ui/;
            autoindex on; # 开启浏览器功能
        }

记得要重启服务。

4、上传图片

5、访问地址

IP地址/images/图片名称

效果如下:

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2020-04-29,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 DataScience 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Nginx
    • 1、Nginx中文网
      • 2、 安装
        • 3、部署静态图片
          • 4、上传图片
            • 5、访问地址
            领券
            问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档