Question

Cant deploy my static web App which includes some PHP scripts

Posted June 4, 2020 208 views
Nginx

Hi All,

Can anyone help me how to configure Nginx conf file? I am trying to deploy my static web app which consists of a small PHP script. I followed tutorials given on digital community portal but not able to figure it out. I added index.php but as of I am not able to execute the file and every time asks me to download.

3 comments
  • 2020/06/04 17:16:26 [emerg] 4574#4574: "fastcgi_pass" directive is not allowed here in /etc/nginx/sites-enabled/default:60
    2020/06/04 17:22:02 [emerg] 4608#4608: unexpected "}" in /etc/nginx/sites-enabled/default:70
    2020/06/04 17:22:51 [emerg] 4629#4629: unexpected "}" in /etc/nginx/sites-enabled/default:70
    2020/06/04 17:23:26 [emerg] 4634#4634: "listen" directive is not allowed here in /etc/nginx/sites-enabled/default:72
    2020/06/04 17:23:34 [emerg] 4655#4655: "listen" directive is not allowed here in /etc/nginx/sites-enabled/default:72
    2020/06/04 17:27:42 [emerg] 4664#4664: "location" directive is not allowed here in /etc/nginx/sites-enabled/default:68
    2020/06/04 17:27:47 [emerg] 4684#4684: "location" directive is not allowed here in /etc/nginx/sites-enabled/default:68
    2020/06/04 17:28:11 [emerg] 4685#4685: "listen" directive is not allowed here in /etc/nginx/sites-enabled/default:72
    2020/06/04 17:29:08 [emerg] 4687#4687: "listen" directive is not allowed here in /etc/nginx/sites-enabled/default:72
    2020/06/04 17:29:24 [emerg] 4688#4688: "listen" directive is not allowed here in /etc/nginx/sites-enabled/default:73
    2020/06/04 17:29:35 [warn] 4689#4689: duplicate value "TLSv1" in /etc/letsencrypt/options-ssl-nginx.conf:10
    2020/06/04 17:29:35 [warn] 4689#4689: duplicate value "TLSv1.1" in /etc/letsencrypt/options-ssl-nginx.conf:10
    2020/06/04 17:29:35 [warn] 4689#4689: duplicate value "TLSv1.2" in /etc/letsencrypt/options-ssl-nginx.conf:10
    2020/06/04 17:29:35 [emerg] 4689#4689: "ssl_prefer_server_ciphers" directive is duplicate in /etc/letsencrypt/options-ssl-nginx.conf:11
    2020/06/04 17:30:10 [emerg] 4693#4693: "listen" directive is not allowed here in /etc/nginx/sites-enabled/default:72
    2020/06/04 17:32:44 [emerg] 4720#4720: "listen" directive is not allowed here in /etc/nginx/sites-enabled/default:72
    2020/06/04 17:36:58 [emerg] 4732#4732: "listen" directive is not allowed here in /etc/nginx/sites-enabled/default:72
    2020/06/04 17:37:15 [warn] 4733#4733: duplicate value "TLSv1" in /etc/letsencrypt/options-ssl-nginx.conf:10
    2020/06/04 17:37:15 [warn] 4733#4733: duplicate value "TLSv1.1" in /etc/letsencrypt/options-ssl-nginx.conf:10
    2020/06/04 17:37:15 [warn] 4733#4733: duplicate value "TLSv1.2" in /etc/letsencrypt/options-ssl-nginx.conf:10
    2020/06/04 17:37:15 [emerg] 4733#4733: "ssl_prefer_server_ciphers" directive is duplicate in /etc/letsencrypt/options-ssl-nginx.conf:11
    
    edited by MattIPv4
  • Those are the error logs generated

  • This is conf file..

    ##
    # You should look at the following URL's in order to grasp a solid understanding
    # of Nginx configuration files in order to fully unleash the power of Nginx.
    # https://www.nginx.com/resources/wiki/start/
    # https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
    # https://wiki.debian.org/Nginx/DirectoryStructure
    #
    # In most cases, administrators will remove this file from sites-enabled/ and
    # leave it as reference inside of sites-available where it will continue to be
    # updated by the nginx packaging team.
    #
    # This file will automatically load configuration files provided by other
    # applications, such as Drupal or Wordpress. These applications will be made
    # available underneath a path with that package name, such as /drupal8.
    #
    # Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
    ##
    
    # Default server configuration
    #
    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 /srv/www/joshiviral.com;
    
        # Add index.php to the list if you are using PHP
        index index.php index.html index.html index.nginx-debian.html;  
    
        server_name www.joshiviral.com joshiviral.com;
    
        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:/var/run/php/php7.2-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;
        #}
    
        #listen [::]:443 ssl ipv6only=on; # managed by Certbot
        #listen 443 ssl; # managed by Certbot
        #ssl_certificate /etc/letsencrypt/live/joshiviral.com/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/joshiviral.com/privkey.pem; # managed by Certbot
        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
    
    
    
    
    }
    
    
    # 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 www.joshiviral.com joshiviral.com;
    #
    root /srv/www/joshiviral.com;
    index index.php index.html index.html index.nginx-debian.html;
    #
    #   location / {
    #       try_files $uri $uri/ =404;
        }
    }
    
    server {
        if ($host = www.joshiviral.com) {
            return 301 https://$host$request_uri;
        } # managed by Certbot
    
    
        if ($host = joshiviral.com) {
            return 301 https://$host$request_uri;
        } # managed by Certbot
    
    
        listen 80 default_server;
        listen [::]:80 default_server;
    
        server_name www.joshiviral.com joshiviral.com;
      return 404; # managed by Certbot
    
    }
    
    edited by MattIPv4

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

Hi @viraljayeshjoshi94,

It seems you’ve deployed all your Nginx server blocks in the /etc/nginx/sites-enabled/default file. For this to work, you’ll need to create a separate .conf file for your domain.

If you are uncertain how to do this, DigitalOcean has a pretty good tutorial on how to actually achieve exactly what you need.

https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-virtual-hosts-on-ubuntu-16-04

In the tutorial for demonstration purposes,two domains are going to be set up with Nginx. The domain names used in this guide are example.com and test.com. I believe it will be really beneficial and will help you create the new conf for yourself as well.

Regards,
KDSys

by Justin Ellingwood
When using the Nginx web server, server blocks (similar to the virtual hosts in Apache) can be used to encapsulate configuration details and host more than one domain off of a single server. In this guide, we'll discuss how to configure server blocks in Nginx on an Ubuntu...
  • Thank you so much!! It is working.

    • I’m glad to hear that!

      Can you confirm what was the exact problem or did you re-do the whole thing?

      • The problem was as you told earlier, there was a conflict with my domain name as of I was deploying all on the same conf file. Actually, I followed the tutorial you suggested and it’s working perfectly. Though one thing to ask you again. I have PHP files on the same directory but seems they are not rendered on the browser instead downloading every time.

Submit an Answer