将具体业务和底层逻辑解耦的组件。
大致的效果是:
需要利用服务的人(前端写业务的),不需要知道底层逻辑(提供服务的)的具体实现,只要拿着中间件结果来用就好了。
举个例子:
我开了一家炸鸡店(业务端),然而周边有太多屠鸡场(底层),为了成本我肯定想一个个比价,再综合质量挑选一家屠鸡场合作(适配不同底层逻辑)。由于市场变化,合作一段时间后,或许性价比最高的屠鸡场就不是我最开始选的了,我又要重新和另一家屠鸡场合作,进货方式、交易方式等等全都要重来一套(重新适配)。
然而我只想好好做炸鸡,有性价比高的肉送来就行。于是我找到了一个专门整合屠鸡场资源的第三方代理(中间件),跟他谈好价格和质量后(统一接口),从今天开始,我就只需要给代理钱,然后拿肉就行。代理负责保证肉的质量,至于如何根据实际性价比,选择不同的屠鸡场,那就是代理做的事了。
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
之后我们列出nginx的版本:
yum list | grep nginx
collectd-nginx.x86_64 5.8.0-1.el7 epel
munin-nginx.noarch 2.0.33-1.el7 epel
nextcloud-nginx.noarch 10.0.4-2.el7 epel
nginx.x86_64 1:1.12.2-1.el7_4.ngx nginx
nginx-all-modules.noarch 1:1.12.2-1.el7 epel
nginx-debug.x86_64 1:1.8.0-1.el7.ngx nginx
nginx-debuginfo.x86_64 1:1.12.2-1.el7_4.ngx nginx
nginx-filesystem.noarch 1:1.12.2-1.el7 epel
nginx-mod-http-geoip.x86_64 1:1.12.2-1.el7 epel
nginx-mod-http-image-filter.x86_64 1:1.12.2-1.el7 epel
nginx-mod-http-perl.x86_64 1:1.12.2-1.el7 epel
nginx-mod-http-xslt-filter.x86_64 1:1.12.2-1.el7 epel
nginx-mod-mail.x86_64 1:1.12.2-1.el7 epel
nginx-mod-stream.x86_64 1:1.12.2-1.el7 epel
nginx-module-geoip.x86_64 1:1.12.2-1.el7_4.ngx nginx
nginx-module-geoip-debuginfo.x86_64 1:1.12.2-1.el7_4.ngx nginx
nginx-module-image-filter.x86_64 1:1.12.2-1.el7_4.ngx nginx
nginx-module-image-filter-debuginfo.x86_64
1:1.12.2-1.el7_4.ngx nginx
nginx-module-njs.x86_64 1:1.12.2.0.1.14-1.el7_4.ngx nginx
nginx-module-njs-debuginfo.x86_64 1:1.12.2.0.1.14-1.el7_4.ngx nginx
nginx-module-perl.x86_64 1:1.12.2-1.el7_4.ngx nginx
nginx-module-perl-debuginfo.x86_64 1:1.12.2-1.el7_4.ngx nginx
nginx-module-xslt.x86_64 1:1.12.2-1.el7_4.ngx nginx
nginx-module-xslt-debuginfo.x86_64 1:1.12.2-1.el7_4.ngx nginx
nginx-nr-agent.noarch 2.0.0-12.el7.ngx nginx
owncloud-nginx.noarch 9.1.5-1.el7 epel
pcp-pmda-nginx.x86_64 3.11.8-7.el7 os
python2-certbot-nginx.noarch 0.20.0-1.el7 epel
我们用加下划线的版本
yum install nginx
对nginx进行安装
nginx -v //查看当前nginx版本
nginx -V //看到编译的参数
[root@VM_69_65_centos ~]# rpm -ql nginx
/etc/logrotate.d/nginx
/etc/nginx
/etc/nginx/conf.d
/etc/nginx/conf.d/default.conf
/etc/nginx/fastcgi_params
/etc/nginx/scgi_params
/etc/nginx/uwsgi_params
/etc/nginx/koi-utf
/etc/nginx/koi-win
/etc/nginx/mime.types
/etc/nginx/modules
/etc/nginx/nginx.conf
/etc/nginx/win-utf
/etc/sysconfig/nginx
/etc/sysconfig/nginx-debug
/usr/lib/systemd/system/nginx-debug.service
/usr/lib/systemd/system/nginx.service
/usr/lib64/nginx
/usr/lib64/nginx/modules
/usr/libexec/initscripts/legacy-actions/nginx
/usr/libexec/initscripts/legacy-actions/nginx/check-reload
/usr/libexec/initscripts/legacy-actions/nginx/upgrade
/usr/sbin/nginx
/usr/sbin/nginx-debug
/usr/share/doc/nginx-1.12.2
/usr/share/doc/nginx-1.12.2/COPYRIGHT
/usr/share/man/man8/nginx.8.gz
/usr/share/nginx
/usr/share/nginx/html
/usr/share/nginx/html/50x.html
/usr/share/nginx/html/index.html
/var/cache/nginx
/var/log/nginx
安装目录讲解:
/etc/nginx/mime.types
设置http协议的Content-Type与扩展名对应关系
/etc/sysconfig/nginx
/etc/sysconfig/nginx-debug
/usr/lib/systemd/system/nginx-debug.service
/usr/lib/systemd/system/nginx.service
用于配置出系统守护进程管理器管理方式
/etc/nginx/modules
/usr/lib64/nginx/modules
Nignx模块目录
/usr/sbin/nginx
/usr/sbin/nginx-debug
Nginx服务启动管理终端命令
/usr/share/doc/nginx-1.12.2
/usr/share/doc/nginx-1.12.2/COPYRIGHT
/usr/share/man/man8/nginx.8.gz
Nginx的手册和帮助文件
/var/cache/nginx
Nginx的缓存目录
/var/log/nginx
Nginx的日志目录
[root@VM_69_65_centos ~]# nginx -V
nginx version: nginx/1.12.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'
-prefix =/etc/nginx
--sbin-path=/usr/sbin/nginx
--modules-path=/usr/lib64/nginx/modules
--conf-path=/etc/nginx/nginx.conf
--error-log-path=/var/log/nginx/error.log
--lock-path=/var/run/nginx.lock
安装目的目录或路径
--------------------------------------------------------------------------------------------------------------
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/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 /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65; //超时时间65S
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
server {
listen 80; //监听的端口是80
server_name localhost;//server的服务名
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/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 /usr/share/nginx/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;
#}
}