nginx 配置

原创
2022/08/19 07:38
阅读数 97
  • 启动nginx容器
docker run --rm -it -p 8181:80 nginx:alpine /bin/sh
# 在容器内启动nginx
nginx

  • 修改nginx配置
 cat  /etc/nginx/conf.d/default.conf
server {
    listen       80;
    server_name  localhost;

    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        #root   /usr/share/nginx/html;
        root /data/www;
        #index  index.html index.htm;
    }
    location /images {
        root /data/;
    }
    #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   /usr/share/nginx/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;
    #}
}


  • 重新加载nginx配置
nginx -s reload
  • 创建测试文件
~ # mkdir -p /data/images
~ # cd /data/images
/data/images # echo 'hello world' > 1.html
  • 验证配置效果
 curl http://127.0.0.1:8181/images/1.html
hello world
展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部