Nginx server configuration problem

pasansnoop

Well-known member
  • Sep 13, 2008
    9,092
    1
    6,967
    113
    TrapHouse
    machan is there anybody who knows how to configure nginx to use php on a server?
    after doing everything, I get '502 Bad Gateway' error from the server :oo:
    i'm stuck for a day troubleshooting the error but couldn't find any..

    this is the guide I followed> https://www.techsupportpk.com/2019/04/how-to-set-up-lemp-stack-ubuntu-1904.html

    can you spot any fault in this config? (which I've linked to /etc/nginx/sites-enabled/)

    NGINX:
    server {
            listen 80;
            root /var/www/html;
            index index.php index.html index.htm index.nginx-debian.html;
            server_name localhost;
    
            location / {
                    try_files $uri $uri/ =404;
            }
    
            location ~ \.php$ {
                    include snippets/fastcgi-php.conf;
                    fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
            }
    
            location ~ /\.ht {
                    deny all;
            }
    }
     
    • Like
    Reactions: kinkon

    pasansnoop

    Well-known member
  • Sep 13, 2008
    9,092
    1
    6,967
    113
    TrapHouse
    thanks machan..
    nginx -t
    service nginx restart
    Restart php fpm
    service php8.1-fpm restart
    already tried that machan
    log eka baluwada ???
    tama na machan.. mama lokuwata danne na me seen eka
    php-fpm eka sock ekata bind welada balanna. Port ekata nam bind wela thiyenne nginx config eka ekata galapenna danna,
    https://stackoverflow.com/questions/17570658/how-to-find-my-php-fpm-sock
    ow meka thamai mage next step eka.. thanks ban
     

    siri_ayya

    Well-known member
  • Feb 1, 2022
    16,966
    1
    29,883
    113
    Php server එකේ error එකක් වැදිලා ඇති අනිවා.. Log එකේ error වැදිලා තියෙනවා නම් ඒ ටික copy කරලා දාන්න..

    මට මේ seen ඒක ගිය සතියේ උනා.. බලද්දී tomcat එකේ ssl config එක වරද්දලා..
     
    • Like
    Reactions: pasansnoop

    pasansnoop

    Well-known member
  • Sep 13, 2008
    9,092
    1
    6,967
    113
    TrapHouse
    Php server එකේ error එකක් වැදිලා ඇති අනිවා.. Log එකේ error වැදිලා තියෙනවා නම් ඒ ටික copy කරලා දාන්න..

    මට මේ seen ඒක ගිය සතියේ උනා.. බලද්දී tomcat එකේ ssl config එක වරද්දලා..
    pm kala machan log eka
     
    Last edited:

    pasansnoop

    Well-known member
  • Sep 13, 2008
    9,092
    1
    6,967
    113
    TrapHouse
    mama itapasse nginx/sites-available/ folder eke hadapu custom config file eka remove karala default eka link kala aith..
    dan 403 forbidden error eka enne na..
    dan ip eka enter kalama browser eken index.php eka download karanawa :baffled:

    me config eka harida balanako..

    Code:
    server {
            listen 80 default_server;
            listen [::]:80 default_server;
    
            # SSL configuration
            #
            # listen 443 ssl default_server;
            # listen [::]:443 ssl default_server;
            #
            # Note: You should disable gzip for SSL traffic.
            # See: https://bugs.debian.org/773332
            #
            # Read up on ssl_ciphers to ensure a secure configuration.
            # See: https://bugs.debian.org/765782
            #
            # Self signed certs generated by the ssl-cert package
            # Don't use them in a production server!
            #
            # include snippets/snakeoil.conf;
    
            root /var/www/html;
          
            # Add index.php to the list if you are using PHP
            index index.php index.html index.htm index.nginx-debian.html;
    
            server_name _;
    
            location / {
                    # First attempt to serve request as file, then
                    # as directory, then fall back to displaying a 404.
                    try_files $uri $uri/ =404;
            }
    
            # pass PHP scripts to FastCGI server
            #
            #location ~ \.php$ {
            #       include snippets/fastcgi-php.conf;
            #
            #       # With php-fpm (or other unix sockets):
            #       fastcgi_pass unix:/run/php/php7.4-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;
            #}
    }
    
    
    # Virtual Host configuration for example.com
    #
    # You can move that to a different file under sites-available/ and symlink that
    # to sites-enabled/ to enable it.
    #
    #server {
    #       listen 80;
    #       listen [::]:80;
    #
    #       server_name example.com;
    #
    #       root /var/www/example.com;
    #       index index.html;
    #
    #       location / {
    #               try_files $uri $uri/ =404;
    #       }
    #}
     

    kosandpol

    Well-known member
  • Jun 10, 2008
    45,329
    1,492
    113
    ubuntu machan..
    full permission deela baluwa 777..
    dan aula thiyenne site ekata giyama php file eka download wenawa..
    browser eken open wenne na
    do you have any idea what you are doing ?
    If you just want a working PHP environment perhaps look at getting a working LAMP stack on that server.
    Ubuntu natively supports LAMP and can be installed from apt

    Or install a control panel such as Virtualmin, which will also give you LAMP and the ability to host multiple domains and control it via a browser based control panel