django-aliyun-oss2-storage icon indicating copy to clipboard operation
django-aliyun-oss2-storage copied to clipboard

nginx配置oss

Open cyberchao opened this issue 6 years ago • 1 comments

你好,我在本地测试没有问题,部署到阿里云上出现504,我怀疑是nginx找不到media了,但是如何把media路径修改成oss呢,这是我现在的配置: `# the upstream component nginx needs to connect to upstream django { server unix://opt/uwsgitest/NewBlog/blog.sock; # for a file socket # server 127.0.0.1:8001; # for a web port socket (we'll use this first) # server oss-cn-shanghai.aliyuncs.com; }

configuration of the server

server { # the port your site will be served on listen 80; # the domain name it will serve for server_name pandacoder.top; # substitute your machine's IP address or FQDN charset utf-8;

# max upload size
client_max_body_size 75M;   # adjust to taste

# Django media
location /Blog_media  {
    proxy_pass http://pandacoderblog.oss-cn-shanghai.aliyuncs.com;
    #alias /opt/uwsgitest/media_root;  # your Django project's media files - amend as required
}

location /static {
    alias /opt/uwsgitest/NewBlog/static_root; # your Django project's static files - amend as required
}

# Finally, send all non-media requests to the Django server.
location / {
    uwsgi_pass  django;

proxy_pass http://pandacoderblog.oss-cn-shanghai.aliyuncs.com;

    include     /opt/uwsgitest/NewBlog/uwsgi_params; # the uwsgi_params file you installed
}

} `

cyberchao avatar Apr 22 '19 10:04 cyberchao

# the upstream component nginx needs to connect to
upstream django {
    server unix://opt/uwsgitest/NewBlog/blog.sock; # for a file socket
    # server 127.0.0.1:8001; # for a web port socket (we'll use this first)
    # server oss-cn-shanghai.aliyuncs.com;
}

# configuration of the server
server {
    # the port your site will be served on
    listen      80;
    # the domain name it will serve for
    server_name pandacoder.top; # substitute your machine's IP address or FQDN
    charset     utf-8;

    # max upload size
    client_max_body_size 75M;   # adjust to taste

    # Django media
    location /Blog_media  {
        proxy_pass http://pandacoderblog.oss-cn-shanghai.aliyuncs.com;
        #alias /opt/uwsgitest/media_root;  # your Django project's media files - amend as required
    }

    location /static {
        alias /opt/uwsgitest/NewBlog/static_root; # your Django project's static files - amend as required
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass  django;
#       proxy_pass http://pandacoderblog.oss-cn-shanghai.aliyuncs.com;
        include     /opt/uwsgitest/NewBlog/uwsgi_params; # the uwsgi_params file you installed
    }
}

cyberchao avatar Apr 22 '19 10:04 cyberchao