1. Instale a ferramenta de download
yum install wget
2. Baixe o nginx
wget http: / / nginx. org/ download/ nginx- 1.10 .2 . tar. gz
3. Descompacte
tar - xvf nginx- 1.10 .2 . tar. gz
4. compilar
. /configure && make && make install
Um erro pode ser relatado durante o processo de compilação, porque algumas dependências não foram baixadas, você pode tentar instalar as dependências com o seguinte comando primeiro, pode haver muitas outras dependências, consulte o relatório de erros para obter detalhes e use o acima comando para compilar
yum install - y pcre- devel zlib- devel openssl- devel
5. A compilação é semelhante ao software de instalação na janela, e a compilação instalará automaticamente o software no diretório especificado /usr/local/
这是nginx的安装目录
/ usr/ local/ nginx
手动启动试试,启动完毕,网页打开ip的80 端口,看是不是能够访问,如果不能访问可能是防火墙的问题,关闭防火墙试试
. /usr/ local/ nginx/ sbin/ nginx
5.1 Existem arquivos de configuração no diretório de instalação do 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 No próximo artigo, adicionarei como adicionar o nginx à unidade de gerenciamento, para usar systemctl para controlar o nginx, e também é muito conveniente configurar a inicialização