V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
hongshaoyuancn
V2EX  ›  Python

大佬们 小弟搭环境关于 nginx+uwsgi+django 的问题!求助!

  •  
  •   hongshaoyuancn ·
    honsy · 2018-03-15 18:23:05 +08:00 · 2142 次点击
    这是一个创建于 2227 天前的主题,其中的信息可能已经有所发展或是发生改变。

    django+uwsgi linux 下环境

    直接上配置

    [uwsgi] set fileencodings=utf-8,gb2312,gb18030,gbk,ucs-bom,cp936,latin1 #project dic chdir=/usr/local/Yshoog/ #application module=Yshoog.wsgi:application #sock dic socket = /usr/local/script/uwsgi.sock #work num workers = 5 pidfile=/usr/local/script/uwsgi.pid #ip http=0.0.0.0:8000 #static static-map=/static=/usr/local/Yshoog/static #group uid=root gid=root #main queue master=true #remove unix socket vacuum=true #xuliehua thunder-locak=true

    harakiri=30 #buffer post-buffering=4096 #log daemonize=/usr/local/script/uwsgi.log

    Nginx 贴一部分

    #Mobile Server
    server {
        listen 80;
        server_name m.yshoog.com;
        location /{
            root m;
            index index.html index.htm;
        }
    }
    #PC Admin
    server {
        listen 80;
        server_name admin.yshoog.com;
        location /static/ {
                root usr/local/Yshoog/static;
        }
        location / {
                proxy_pass http://127.0.0.1:8000;
                proxy_pass_header Server;
                proxy_set_header Host   $host:83;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Scheme $scheme;
        }
    }
    

    django 死活访问不到 static 文件 nginx 怎么匹配 url 都不行 求大神解解惑啊 一下午 快崩了

    第 1 条附言  ·  2018-03-16 08:41:40 +08:00
    现在直接访问 admin.yshoog.com:8000 端口是没问题的 就是我想知道 nginx 怎么配置 能让 admin.yshoog.com 转向 admin.yshoog.com:8000 这个端口 并且静态文件都存在的。。。。。
    9 条回复    2018-03-16 09:50:57 +08:00
    hongshaoyuancn
        1
    hongshaoyuancn  
    OP
       2018-03-15 18:24:01 +08:00
    admin.yshoog.com 这个到现在都没有反应 我先回家了 回家再看啊
    hongshaoyuancn
        2
    hongshaoyuancn  
    OP
       2018-03-15 18:24:15 +08:00
    求大神解解惑啊
    watzds
        3
    watzds  
       2018-03-15 18:25:34 +08:00 via Android
    好,你先回家吧
    crb912
        4
    crb912  
       2018-03-15 18:38:39 +08:00
    这个贴和你的问题类似吗? https://www.v2ex.com/t/437768
    peinstrike
        5
    peinstrike  
       2018-03-16 01:12:56 +08:00
    我猜,这个路径 usr/local/Yshoog/static 前面少个斜杠。
    找错误原因最好把错误信息发出来。
    hongshaoyuancn
        6
    hongshaoyuancn  
    OP
       2018-03-16 08:36:54 +08:00
    @peinstrike 这个改了也米什么用 错误信息是 nginx 404 not found 应该就是 /static/这个没有被转发到 /usr/local/Yshoog/static 这个路径下
    jsnjfz
        7
    jsnjfz  
       2018-03-16 09:16:45 +08:00
    本地启动 django 能访问到么
    hongshaoyuancn
        8
    hongshaoyuancn  
    OP
       2018-03-16 09:19:12 +08:00
    已解决 谢谢大家 直接转发了端口 实在是弄不懂这个 uwsi_params 的配置

    直接转发到 8000 端口了 copy 的配置

    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Real-Ip $remote_addr;
    proxy_set_header X-NginX-Proxy true;
    proxy_pass http://127.0.0.1:8000/;
    proxy_redirect off;
    Hasal
        9
    Hasal  
       2018-03-16 09:50:57 +08:00   ❤️ 1
    ```bash
    location /static/ {
    root usr/local/Yshoog/static;
    }
    ```
    这里配置有问题,首先最基本的,绝对路径错误,开头少了斜杠;
    第二,root 和 alias 是有区别的,你这里应该用的是
    ```bash
    root /usr/local/Yshoog/
    ```

    ```bash
    alias /usr/local/Yshoog/static/
    ```
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2543 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 01:17 · PVG 09:17 · LAX 18:17 · JFK 21:17
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.