404 Not Found nginx/1.18.0(Ubuntu)on running django rest framework with EC2沿着with gunicorn,nginx and Supervisor

umuewwlo  于 2023-08-03  发布在  Nginx
关注(0)|答案(1)|浏览(336)

所以我在AWS EC2上托管了我的Django REST框架项目。我集成了nginx,gunicorn和Supervisor。在它显示成功配置后,唯一起作用的链接是默认链接。示例http://35.154.109.114/工作,但任何其他URL说http://35.154.109.114/test不工作当我使用标准gunicorn --bind 0.0.0.0:8000 DemoProject.wsgi:application命令时,这些链接如何工作。请让我知道如何解决这个问题。我的主urls.py

from django.contrib import admin
from django.urls import path
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
from django.conf.urls import URL
from django.views.static import serve


urlpatterns = [

url(r'^media/(?P<path>.*)$', serve,{'document_root': settings.MEDIA_ROOT}),
url(r'^static/(?P<path>.*)$', serve,{'document_root': settings.STATIC_ROOT}),
path('admin/', admin.site.urls),
path('', include('main.urls')),
path('', include('poultryapp.urls')),
path('', include('Vet.urls')),
path('', include('call_module.urls')),
path('', include('payment.urls')),
path('', include('adminApp.urls')),
path('', include('community.urls')),
path('', include('sdk.urls')),
path('', include('cooperative.urls')),
]+ static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)

urlpatterns += static(settings.STATIC_URL,document_root=settings.STATIC_ROOT)

字符串
我在给出sudo nano /etc/nginx/sites-available/default命令后编辑的nginx配置文件:

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    root /var/www/html/;
    index index.php index.html index.htm index.nginx-debian.html;

    server_name 35.154.109.114/;

    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            include proxy_params;
            proxy_pass http://unix:/var/www/html/api.drpashu/app.sock;
            try_files $uri $uri/ =404;
    }

    # pass PHP scripts to FastCGI server
    #
    location /static/ {
            autoindex on;
            alias /var/www/html/api.drpashu/static/;
    }

    location ~ \.php$ {
            include snippets/fastcgi-php.conf;
    #       
            # With php-fpm (or other unix sockets):
            fastcgi_pass unix:/run/php/php8.1-fpm.sock;
    #       # With php-cgi (or other tcp sockets):
    #       fastcgi_pass 127.0.0.1:9000;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
            deny all;
    }


{\fnSimHei\bord1\shad1\pos(200,288)}
如果有助于更好地理解,我使用了these指令集。我做的一切都和上面提到的完全一样,除了把数据库改为mySQL。

xoefb8l8

xoefb8l81#

您希望代理传递到supervisord正在运行的gunicorn服务。proxy_pass http://127.0.0.1:8000;。现在您指向的不是它看起来像的gunicorn服务。我也强烈建议你打开nginx服务器的日志记录,这样你就可以更容易地解决这类问题。

access_log   /var/log/nginx/some_site.access.log;
error_log    /var/log/nginx/some_site.error.log;
location / {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $host;
    proxy_redirect off;
    if (!-f $request_filename) {
        proxy_pass http://some_server_def;
        break;
    }
}

字符串

相关问题