1.安装下载工具
yum install wget
2.下载 nginx
wget http://nginx.org/download/nginx-1.10.2.tar.gz
3. 解压
tar -xvf nginx-1.10.2.tar.gz
4.编译
./configure && make && make install
编译过程可能或报错,因为有些依赖没有下载,可以试下先用以下命令安装依赖,有可能有很多其他依赖,具体看报错,再用以上命令进行编译
yum install -y pcre-devel zlib-devel openssl-devel
5.编译类似window中的安装软件,编译会自动把软件安装到指定的目录 /usr/local/
这是nginx的安装目录
/usr/local/nginx
手动启动试试,启动完毕,网页打开ip的80端口,看是不是能够访问,如果不能访问可能是防火墙的问题,关闭防火墙试试
./usr/local/nginx/sbin/nginx
5.1 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 /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.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 下一文章,我将补充怎么把nginx加入到管理单元,以便使用systemctl 来控制nginx,也可以很方便的设置开机启动
版权声明:本文为weixin_45475798原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。