nginx

一、网上参考资料

  1、Ubuntu 16.04安装Nginx

  2、使用nginx搭建简单文件服务器

  3、Nginx 配置详解

  4、nginx快速入门之配置篇

  5、Ubuntu上使用nginx搭建https文件服务器

  6、nginx-rtmp-module的缺陷分析

  7、使用docker安装nginx

  8. 用Nginx快速搭建文件服务器(主要参考文档)

  9. 使用Nginx进行TCP/UDP端口转发

  10. Nginx(三)------nginx 反向代理 

二、实践

  1、用docker部署nginx

sudo docker search nginx
sudo docker pull nginx
sudo docker images
sudo docker run -d --name mynginx -p 8080:80 nginx:latest
sudo docker ps
sudo docker exec -it mynginx /bin/bash

 

  2. 在虚拟机下搭建nginx文件服务器:

    2.1 安装nginx

sudo apt-get install nginx

    2 .2 创建单独的conf文件或者修改/etc/nginx/nginx.conf文件

    2.2.1: 创建单独的conf文件如下

sudo vim /etc/nginx/conf.d/file_server.conf

      其文件服务器的端口为8080,可以通过网页浏览或者wget方式下载,如:wget http://192.168.128.71:8080/12.txt:

server {
    listen  8080;
    server_name    127.0.0.1; # 自己PC的ip或者服务器的域名
    charset utf-8; # 避免中文乱码
    root /home/xx/share;
    location / {
        autoindex on; # 索引
        autoindex_exact_size on; # 显示文件大小
        autoindex_localtime on; # 显示文件时间
    }
}

     2.2.2:修改/etc/nginx/nginx.conf文件的http服务: 

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       8081;
        server_name  localhost;
        charset utf-8;

        #access_log  logs/host.access.log  main;

        location / {
            root  /opt/www/html;
            autoindex on;
        #    index  index.html index.htm;
        }

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

 

   2.3  测试配置文件

//测试配置文件  sudo /usr/sbin/nginx -t 
//重新加载配置文件   sudo /etc/init.d/nginx reload

 

   2.4 重启nginx和查看状态

sudo /etc/init.d/nginx restart
sudo /etc/init.d/nginx status

     2.5 通过浏览器访问文件服务器,输入网址:

http://192.168.22.71:8080

 

posted @ 2020-09-09 17:07  shanyu20  阅读(98)  评论(0)    收藏  举报