Bubka / 2FAuth

A Web app to manage your Two-Factor Authentication (2FA) accounts and generate their security codes
https://docs.2fauth.app/
GNU Affero General Public License v3.0
2.13k stars 142 forks source link

Getting 502 Bad gateway #353

Closed tejas3005 closed 3 months ago

tejas3005 commented 3 months ago

Version

latest

Details & Steps to reproduce

i have setup 2FA in my local development env on ubuntu-20.04 i have nginx as server and i am able to access it on http://localhost:8000/ when i run using php artisan serve but when i run using command php artisan 2fauth:install and access it on http://localhost i am getting 502 bad gateway error i have followed steps for self hosted server, earlier i followed same steps using apache as web server on which everything is running fine and as expected but in nginx i am getting 502 bad gateway error on http://loclhost i tried changing server name to localhost in nginx.conf but still same error also i can't undertsand that in apache web server you given steps to create new virtual host and why not in nginx? please help!!

Expectation

i expect it to run on http://localhost Screenshot 2024-06-29 020127

Error & Logs

No response

Execution environment

No response

Containerization

Additional information

image

Screenshot 2024-06-29 020321 Screenshot 2024-06-29 020342

tejas3005 commented 3 months ago

Screenshot 2024-06-29 020321 Screenshot 2024-06-29 020342

Let me know if you need anything else

kamalmjt commented 3 months ago

Could you tell me what configuration you are running in PHP.

Nginx + PHP-FPM Nginx Has reverse proxy and (Apache + PHP-FPM) Nginx Has reverse proxy and (Apache + mod_php)

and please paste config file here.

Thanks.

tejas3005 commented 3 months ago

Nginx + php-fpm, i have already posted the nginx config file.

events {}

http { include mime.types;

access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log;

server { listen 80; server_name localhost; root /var/www/2fauth/public;

  index index.php;

  charset utf-8;

  location / {
      try_files $uri $uri/ /index.php?$query_string;
      add_header 'Access-Control-Allow-Origin' '*';
      add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
      add_header 'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept, Authorization';

      # Handle preflight requests
      if ($request_method = 'OPTIONS') {
          add_header 'Access-Control-Allow-Origin' '*';
          add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
          add_header 'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept, Authorization';
          add_header 'Access-Control-Max-Age' 1728000;
          add_header 'Content-Type' 'text/plain charset=UTF-8';
          add_header 'Content-Length' 0;
          return 204;
      }
  }

  location = /favicon.ico { access_log off; log_not_found off; }
  location = /robots.txt  { access_log off; log_not_found off; }

  error_page 404 /index.php;

  location ~ \.php$ {
      fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
      fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
      include fastcgi_params;
      add_header 'Access-Control-Allow-Origin' '*';
      add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
      add_header 'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept, Authorization';
  }

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

} }

kamalmjt commented 3 months ago

Please can you give me the output of these commands.

Profound-git commented 3 months ago

Hi Managed to fix it now o am able to view login and registration page but i am getting error while registration

Note: i added ssl certificates to access it via https

image

Profound-git commented 3 months ago

HI, I managed to fix all issues we can close this thread now, thanks for your help @kamalmjt :)