Загрузка...

Install Config Getting Started with NGINX on Linux

Installing NGINX:
How you can install nginx on a fresh linux machine:
1. through a repository YUM / APT-GET
2. Compiling from source

Connect to your linux server:
Commands:
Check and verify if nginx is installed.

rpm -qa | grep nginx

If you get a blank reply it means nginx is not installed.

Verify if you have a epel reslease package:

rpm -qa | grep epel-release

If epel is not installed use command:

apt-get install epel-release

and now install nginx using command:

apt install nginx -y

Now go to the nginx directory for configurations:
Do this command to go to the nginx directory:

cd/etc/nginx
Check the nginx log file:
command:
ls -l /var/log/nginx/error.log

To see the error logs use command:
less /var/log/nginx/error.log

pid means process id:

Using command:
cat /var/run/nginx.pid
Copy the directory from your config file nginx.conf section of where your logs are stored:\

ls -lh /var/www/log/nginx.access.log

The include directive is /etc/nginx/conf.d/*.conf;
example command to view and edit file:
nano /etc/nginx/conf.d/
you will see config files displayed
Open web.conf with command:
nano /etc/nginx/conf.d//web.conf

There is another include directive within this file, check by running command:
ls /etc/nginx/mime.types

Whenever you write a configuration you can test it using the command:
nginx -t

Using this command should give you a fail or no fail result, any errors will give you commands to check the errors further using journal for example.
Configuring our first website using NGINX

You have installed nginx and looked into the basic configuration directives, lets go further open ssh command:

service nginx status

This command will tell you if nginx is running or not.
Nginx by default stores by default index.html in location: /user/share/nginx/index.html so do the command:
cd /user/share/nginx/html

Now do the command:
ls
You will see files

try command:
nano /etc/nginx/nginx.conf
You will see root configuration showing the default website path.

To configure you website you will be using: /etc/nginx/ path/directory

cd /etc/nginx/conf.d

pwd

Should show result of pwd as: /etc/nginx/conf.d

ls

Should show result of ls as:

virtual.conf

Open virtual.conf

nano virtual.conf

You can easily edit basic nginx configuration in this file though we will not be using this for this part of the tutorial.
Create a file for your website and enter it using nano:

nano web.conf

Write in the file:

server {
server_name example.com;

location / {
root /var/www/example.com;
index index.html;
}

Now save the file ctrl O.

Now test the configuration using command:

nginx -t

You should see siucsessful if it is not check the file again for a mistake etc.

Make a directory for your website using command:

mkdir /var/www/example

Then enter the directory using command:

cd /var/www/example

Now create a file called index.html and enter it to edit it using command:

nano index.html

Now in the file simply add the text:

Hey this is the nginx website i have setup!

Save the file.

Change the ownership to nginx for var/www using command:

chown -R nginx.nginx /var/www/example/

Now reload nginx using command:

service nginx reload

Open your web browser to local host or yourwebsitename.com if you changed to your own website instead of example.com.

You should see the message:

Hey this is the nginx website i have setup!

Lets go to the nginx.conf again using command:

cd /etc/nginx/conf.d

Now enter the web.conf file and edit it using command:

nano web.conf
server {
server_name example.com;

location / {
root /var/www/example.com;
index index.html;
}

server {
server_name example.net

You can have multiple server sections and multiple domain sections within the file for example:

server {
server_name example.com

The folders for each domain would be different for example.

Mime Types Explained and Configuring Them with Nginx:

MIME (Multipurpose Internet Mail Extensions) Types.

https://infopirate.xyz/knowledge/Nginx/Zeal%20Vora%20-%20Nginx%20-%20Beginner%20to%20Advanced/03_-_Getting_Started_with_NGINX/NGINX-TRAINING-Getting-Started-with-NGINX.txt

Видео Install Config Getting Started with NGINX on Linux канала ResearchForumOnline
Яндекс.Метрика

На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.

Об использовании CookiesПринять