Home > Software engineering >  Laravel Docker - The POST method is not supported for this route. Supported methods: GET, HEAD
Laravel Docker - The POST method is not supported for this route. Supported methods: GET, HEAD

Time:11-11

I have a codecanyon project, and it can be installed in shared hosting without any error. Works like charm. However I was trying to install the same using docker-compose. I am getting error as "The POST method is not supported"

People have suggested for laravel codefix for such error, however in my case code works in Sharedhosting. I think some issue with the nginx config not the laravel code.

I am not expert, hoping someone can point me out where to dig.

Laravel error stack enter image description here Docker Console enter image description here

enter image description here enter image description here enter image description here

default.conf

server {
    listen 80;
    server_name starhardware.com.my;
    root /var/www/app;
 
    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-Content-Type-Options "nosniff";
 
    index index.php;
 
    charset utf-8;
 
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
 
    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }
 
    
 
    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

nginx.conf

user  www-data;
worker_processes  auto;

error_log  /var/log/nginx/error.log debug;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

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

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

Thank you.

CodePudding user response:

Well.. Initially I was only looking for error at Laravel side. I did more investigation related to nginx and came to this thread.

Laravel routes not found after nginx install

I followed it and it worked. my revised default.conf as below:

server {
    listen 443;
    server_name starhardware.com.my;
    root /var/www/app;
 
    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-Content-Type-Options "nosniff";
 
    index index.php;
 
    charset utf-8;
 
    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }
 
    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }
 
     
    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}
  • Related