ceu-notes/2/SRI/exams/examen-nginx-nortega.txt

111 lines
3.0 KiB
Plaintext
Raw Normal View History

2022-11-02 15:22:54 +00:00
================================
*** Examen de NGinx ***
*** --- ***
*** Nicolás A. Ortega Froysa ***
================================
Guía:
# --- comentario
[usuario@máquina] --- en qué máquina y con qué usuario estamos
$ --- comando shell
Máquinas:
- servidor
- cliente
[examen@servidor]
$ sudo apt install openssh-server
[usuario@cliente]
$ ssh examen@servidor
# de ahora en adelante, todo lo que sea en el lado servidor será con SSH
[examen@servidor]
# cambiamos contraseña de root a 'toor' para facilitar las cosas
$ sudo passwd root
$ su -
[root@servidor]
$ apt update
$ apt install nginx
$ echo "127.0.0.1 esteexamen.es" > /etc/hosts
$ mkdir /var/www/esteexamen.es/
$ cd /etc/nginx/sites-available/
$ cp default esteexamen.es.conf
$ vi esteexamen.es.conf
$ cat esteexamen.es.conf
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/esteexamen.es/;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name esteexamen.es;
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.4-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
#}
}
$ ../sites-enabled
$ rm default
$ ln -s ../sites-available/esteexamen.es.conf ./
# cambiar el puerto
$ sed -Ei 's/80/8505/g' esteexamen.es.conf
$ sed -Ei 's/index .*$/index exameninicio.html;/g' esteexamen.es.conf
$ echo "Bienvenido al examen... empezamos" > /var/www/esteexamen.es/exameninicio.html
$ systemctl restart nginx
$ apt install curl
$ curl esteexamen.es:8505
Bienvenido al examen... empezamos
$ apt install php-fpm
$ vi esteexamen.es.conf
$ cat esteexamen.es.conf
server {
listen 8505 default_server;
listen [::]:8505 default_server;
root /var/www/esteexamen.es/;
# Add index.php to the list if you are using PHP
index exameninicio.html;
server_name esteexamen.es;
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/php-fpm.sock;
}
}
$ echo '<?php echo "Es correcto el php."; ?>' > /var/www/esteexamen.es/info.php
$ systemctl restart nginx
$ curl esteexamen.es:8505/info.php
Es correcto el php.