1. Install the download tool
yum install wget
2. Download nginx
wget http: / / nginx. org/ download/ nginx- 1.10 .2 . tar. gz
3. Unzip
tar - xvf nginx- 1.10 .2 . tar. gz
4. compile
. /configure && make && make install
An error may be reported during the compilation process, because some dependencies have not been downloaded, you can try to install the dependencies with the following command first, there may be many other dependencies, see the error report for details, and then use the above command to compile
yum install - y pcre- devel zlib- devel openssl- devel
5. Compile is similar to the installation software in window, and the compilation will automatically install the software to the specified directory /usr/local/
这是nginx的安装目录
/ usr/ local/ nginx
手动启动试试,启动完毕,网页打开ip的80 端口,看是不是能够访问,如果不能访问可能是防火墙的问题,关闭防火墙试试
. /usr/ local/ nginx/ sbin/ nginx
5.1 There are configuration files in the nginx installation directory
配置文件位置,在这里修改配置
/ 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 In the next article, I will add how to add nginx to the management unit, so as to use systemctl to control nginx, and it is also very convenient to set up the startup