1. Instala la herramienta de descarga
yum install wget
2. Descarga nginx
wget http: / / nginx. org/ download/ nginx- 1.10 .2 . tar. gz
3. Descomprimir
tar - xvf nginx- 1.10 .2 . tar. gz
4. compilar
. /configure && make && make install
Se puede informar un error durante el proceso de compilación, porque algunas dependencias no se han descargado, puede intentar instalar las dependencias con el siguiente comando primero, puede haber muchas otras dependencias, consulte el informe de errores para obtener más detalles y luego use lo anterior comando para compilar
yum install - y pcre- devel zlib- devel openssl- devel
5. La compilación es similar al software de instalación en la ventana, y la compilación instalará automáticamente el software en el directorio especificado /usr/local/
这是nginx的安装目录
/ usr/ local/ nginx
手动启动试试,启动完毕,网页打开ip的80 端口,看是不是能够访问,如果不能访问可能是防火墙的问题,关闭防火墙试试
. /usr/ local/ nginx/ sbin/ nginx
5.1 Hay archivos de configuración en el directorio de instalación de nginx
配置文件位置,在这里修改配置
/ usr/ local/ nginx/ conf/ nginx. conf
这是nginx的配置文件的信息
1 ,一个http下有多个server, 每个server监听一个端口
2 ,一个server下有多个location, 每个location监听一个接口
#user nobody;
worker_processes 1 ;
#error_log logs/ error. log;
#error_log logs/ error. log notice;
#error_log logs/ error. log info;
#pid logs/ nginx. pid;
events {
worker_connections 1024 ;
}
http {
# mime. types; 是一个文件,这里默认的是和配置文件同一个目录
include mime. types;
default_type application/ octet- stream;
#log_format main '$remote_addr - $remote_user [ $time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for" ';
#access_log logs/ access. log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0 ;
keepalive_timeout 65 ;
#gzip on;
server {
listen 80 ;
server_name localhost;
#charset koi8- r;
#access_log logs/ host. access. log main;
location / {
# 以下root 右边的html是一个目录名称,和本conf在同一个目录,如客户访问80 端口的根目录,
nginx就会在html这个目录里寻找 index. html 这个文件,然后渲染给客户看
root html;
index index. html index. htm;
}
#error_page 404 / 404. html;
# redirect server error pages to the static page / 50 x. html
#
error_page 500 502 503 504 / 50 x. html;
location = / 50 x. html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0 .0 .1 : 80
#
#location ~ \. php$ {
# proxy_pass http: / / 127.0 .0 .1 ;
#}
# pass the PHP scripts to FastCGI server listening on 127.0 .0 .1 : 9000
#
#location ~ \. php$ {
# root html;
# fastcgi_pass 127.0 .0 .1 : 9000 ;
# fastcgi_index index. php;
# fastcgi_param SCRIPT_FILENAME / scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to . htaccess files, if Apache 's document root
# concurs with nginx 's one
#
#location ~ / \. ht {
# deny all;
#}
}
server {
listen 81 ;
server_name localhost;
#charset koi8- r;
#access_log logs/ host. access. log main;
location / {
root html;
index index. html index. htm;
} }
}
6 En el próximo artículo, agregaré cómo agregar nginx a la unidad de administración para que systemctl pueda usarse para controlar nginx, y también es muy conveniente configurar el inicio