skip to Main Content

So I was trying to deploy my python-flask app on AWS. I have rented the server and have setup everything. I was using this to do my work of deploying application on AWS server. Up until Step 6 everything was perfect but then as it said in Step 6, I need to add some configurations in default file inside sites-available folder in nginx directory, but in my case I don’t have any sites-available folder, I am using Amazon Linux AMI. Can anyone tell me where to add those configurations mentioned in Step 6 or how to create that default file. I even tried to reinstall nginx but the problem doesn’t solve, no sites-available folder exists.

2

Answers


  1. Try use Ubuntu linux next time, personally think it is way easier to use.

    So sites-available folder is in /etc/nginx/. You can do:

    sudo vi /etc/nginx/sites-available/default, if password required, enter root user password.

    Then input following code:

    server {
        listen       80;
        listen      [::]:80;
        server_name  localhost;
        client_max_body_size 10M;
    
        #charset koi8-r;
    
        #access_log  logs/host.access.log  main;
    
        location / {
            # root   html;
            # index  index.html;
            proxy_pass      http://127.0.0.1:5000;
            proxy_redirect  off;
            
            proxy_set_header    Host                $host;
            proxy_set_header    X-Real-IP           $remote_addr;
            proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;
            proxy_set_header    X-Forwarded-Proto   $scheme;
        }
    

    Then :wq

    Remember to change the PORT if you’re not running flask on 5000.

    Then do ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled.

    Then do sudo vi /etc/nginx/nginx.conf

    Check if include /etc/nginx/sites-enabled/*; is inside http{...} and is not commended

    Then :q to quit

    Then do sudo nginx -s reload if your nginx is running, or do sudo systemctl start nginx if it is not running.

    Then Open http://yourWebsite


    For more details for you to understand nginx:

    This is not necessary

            proxy_set_header    Host                $host;
            proxy_set_header    X-Real-IP           $remote_addr;
            proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;
            proxy_set_header    X-Forwarded-Proto   $scheme;
    

    You can change the default to any other name you want

    Folder sites-available is for the different sites on the server

    Folder sites-enabled is for the shortcuts of files in sites-available

    files in sites-available will be imported through include /etc/nginx/sites-enabled/*; into nginx.conf

    Login or Signup to reply.
  2. Look for include statements in /etc/nginx/nginx.conf to find out which files and directories are scanned for configuration snippets. There might be something like this:

    http {
      ...
      include sites-available/*;  # import any file from /etc/nginx/sites-available
      ...
      include conf.d/*.conf;  # import '*.conf' files from /etc/nginx/conf.d
      ...
    }
    

    You can use this to find out which directory is used or just create your own one.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search