Jump to content
mstdmstdd

Error installing nginx in Ubuntu 18 under AWS

Recommended Posts

Hello,
I installed Ubuntu 18 instance under AWS and I found this article with nginx installation(I used this article with installation in Ubuntu 18 under Digital Ocean)
https://devmarketer.io/learn/deploy-laravel-5-app-lemp-stack-ubuntu-nginx/

I installed nginx, but I am not sure whioch must be servwer name in nginx configurations :

server {
        listen 80 default_server;
        listen [::]:80 default_server;


        root /var/www/html;

        index index.php index.html index.htm index.nginx-debian.html;

        server_name ec2-NN-NN-NN-NN.us-east-2.compute.amazonaws.com;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }


        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        }

        location ~ /\.ht {
                deny all;
        }

where 
my Publick DNS
NN-NN-NN-NN.us-east-2.compute.amazonaws.comI checked nginx syntax and restarted php and nginx

$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
$ sudo systemctl restart php7.2-fpm
$ sudo service nginx restart


But running url
http://NN-NN-NN-NN.us-east-2.compute.amazonaws.com/I got error:

Quote

 

.us-east-2.compute.amazonaws.com’s server IP address could not be found.
DNS_PROBE_FINISHED_NXDOMAIN


 

But not nginx greeting page.
Is it on AWS different and what did I miss?

Thanks!
 

Share this post


Link to post
Share on other sites

The server_name is the domain name of your website. If you want to go to http://ec2-whatever then your server_name would be ec2-whatever.

If DNS isn't resolving yet and you're sure you typed it correctly (so copy/paste it), wait a while and try again.

Share this post


Link to post
Share on other sites

looks  like the problem was that in security group i forgot set httphttps access

If there is a way to set  Multiple Websites on Single instance  with nginx  ?

Share this post


Link to post
Share on other sites

A security group shouldn't prevent DNS from working.

Yes, you can do multiple websites. Guide

  • Thanks 1

Share this post


Link to post
Share on other sites

Thank you for the link, but with quick review I did not find how to create multiple websites under one server?

 

 

Share this post


Link to post
Share on other sites

The page does say, but I'll admit it's not very clear about how.

You've seen the server { } blocks, right? You can have more than one for different server_names and/or listens.

On Debian-based Linux there is typically a /etc/nginx/sites-enabled and sites-available. sites-available is where multiple site configuration files are, and sites-enabled has a symlink to each one that should be enabled.

Share this post


Link to post
Share on other sites


I searched how to install multiple projects on nginx server and found some articles, like
https://medium.freecodecamp.org/how-you-can-host-multiple-domain-names-and-projects-in-one-vps-7aed4f56e7a1

I added new server block with rather long server name(which I created in freenom)
Checking the syntax I got error that server_names_hash_bucket_size must be set to 64

I tried to set and and did not find valid place for it.
I found that it must be added under http block. I tried to add http block in my /etc/nginx/sites-available/default
but got syntax error :

$ sudo nginx -t 
nginx: [emerg] "http" directive is not allowed here in /etc/nginx/sites-enabled/default:22
nginx: configuration file /etc/nginx/nginx.conf test failed

My /etc/nginx/sites-available/default :
 

## 
# 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
#

http {
server_names_hash_bucket_size 64;
}


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/VotesDeploy/public;
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 ec2-rather-long-name.us-east-2.compute.amazonaws.com;

location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.php?$query_string;
}


location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}

location ~ /\.ht {
deny all;
}



# 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.0-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;
#}
}



server {

listen 80;

root /var/www/votes/public;

index index.php index.html index.htm index.nginx-debian.html;

server_name rather-long-name-demo.demo-apps.tk;

location / {
try_files $uri $uri/ /index.php?$query_string;
}


location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}

location ~ /\.ht {
deny all;
}

access_log /var/www/votes/storage/logs;

# server_names_hash_bucket_size 64;

}



# 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;
# }
#}


Which is valid syntax ?

Thanks!

Share this post


Link to post
Share on other sites

Don't edit the default file. Revert it to the original, disable it from sites-enabled, then create a new file in sites-available.

The file only needs one server block, or two if you want http+https support. No http block, that's nginx configuration and would belong somewhere else if you needed one at all.

Share this post


Link to post
Share on other sites

Here. This looks like a reasonable example I just happened to find lying around somewhere.

server {

listen 80;

root /var/www/votes/public;

index index.php index.html index.htm index.nginx-debian.html;

server_name rather-long-name-demo.demo-apps.tk;

location / {
try_files $uri $uri/ /index.php?$query_string;
}


location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}

location ~ /\.ht {
deny all;
}

access_log /var/www/votes/storage/logs;

# server_names_hash_bucket_size 64;

}

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.