Linux服务器Nginx部署图片

版权声明:欢迎转载,转载请注明出处 https://blog.csdn.net/weixin_44649870/article/details/89449053

部署一个静态页面做测试

  • 文件路径是这样的

    .
    └── background
        ├── images
        │   ├── 1.jpg
        │   ├── 2.jpg
        │   └── 3.jpg
        └── index.html
    
  • index.html 中的路径是这样的

    style="background-image:url('/images/1.jpg')"
    
  • /etc/nginx/nginx.conf 是这样的

    server {
            listen 80;
            server_name background.wxy.email;    # 域名/ip
            charset utf-8;
            location / {
                    root /home/www/background;  #  html存储路径
                    index index.html;     #  html名称
            }
            location /images/ {   
                    alias /home/www/background/images/;   # 图片存储路径
                    autoindex on;
            }
        }
    
  • 修改文件夹权限

    sudo chmod 777 -R /home/www/background/
    
  • 启动 / 重启nginx

    sudo service nginx start  # 启动
    sudo service nginx reload  #重启
    
  • 浏览器中输入网址

  • 参考项目:http://background.wxy.email/

猜你喜欢

转载自blog.csdn.net/weixin_44649870/article/details/89449053