開發(fā)安卓app關鍵詞優(yōu)化的發(fā)展趨勢
一.nginx簡介
1.簡介
2.特性
二.nginx安裝
1.rpm包方式
(1)下載擴展源
(2)安裝擴展rpm包,nginx -V查看配置參數,后面源碼安裝時要用到
2.源碼方式
(1)建議提前下好所需要的部分包
(2)下載tar.gz包
(3)建議將包解壓到/usr/local/src下,執(zhí)行configure文件
(4)安裝好上面需要的包,繼續(xù)執(zhí)行第一步?
(5)一直到這步,configure文件就執(zhí)行好了?
(6)make,make install編譯安裝
三.nginx部分目錄結構
1.conf目錄
2.html目錄
四.nginx配置文件說明
一.nginx簡介
1.簡介
nginx是一個輕量級的網頁服務器、方向代理服務器和電子郵件代理服務器,具有配置靈活、靜態(tài)資源高并發(fā)、系統(tǒng)資源占用少、擁有緩存服務等優(yōu)點。
2.特性
(1)對于靜態(tài)資源,高速,高并發(fā)訪問和緩存,支持htto相應速率限制
(2)支持使用反向代理加速,緩存數據
(3)可實現(xiàn)負載均衡和節(jié)點健康檢查
(4)支持FastCGI,SCGI,Memcached Servers等服務的急速和緩存
(5)支持基于域名、端口、IP的虛擬主機站點代理,可以進行訪問控制
(6)支持Keep-alive和pipelined連接
(7)在代碼上線時可以平滑重啟,不影響基本功能
(8)可以對日志進行格式自定義、臨時緩沖、快速輪訓和rsyslog處理
(9)支持信號控制nginx進程
(10)支持url重寫和正則表達式匹配
(11)支持PUT、DELETE、MKCOL、COPY、MOVE等特殊http請求方法
(12)支持郵件服務代理
二.nginx安裝
前提要卸載或關閉apache的httpd
[root@localhost ~]# systemctl stop httpd
[root@localhost ~]# systemctl status httpd
● httpd.service - The Apache HTTP ServerLoaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)Active: inactive (dead)Docs: man:httpd(8)man:apachectl(8)
1.rpm包方式
(1)下載擴展源
(2)安裝擴展rpm包,nginx -V查看配置參數,后面源碼安裝時要用到
[root@localhost ~]# yum install https://nginx.org/packages/centos/7Server/x86_64/RPMS/nginx-debuginfo-1.22.0-1.el7.ngx.x86_64.rpm
[root@localhost ~]# yum install nginx-1.22.0-1.el7.ngx.x86_64.rpm -y
[root@localhost ~]# nginx -v
nginx version: nginx/1.22.0
[root@localhost ~]# nginx -V
nginx version: nginx/1.22.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (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'
安裝完成?
2.源碼方式
(1)建議提前下好所需要的部分包
[root@localhost nginx-1.22.0]# yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
(2)下載tar.gz包
(3)建議將包解壓到/usr/local/src下,執(zhí)行configure文件
[root@localhost nginx-1.22.0]# pwd
/usr/local/src/nginx-1.22.0[root@localhost nginx-1.22.0]# ./configure --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'
#彈出來缺什么就安裝它的開發(fā)包(devel)
(4)安裝好上面需要的包,繼續(xù)執(zhí)行第一步?
[root@localhost nginx-1.22.0]# yum install -y pcre-devel
[root@localhost nginx-1.22.0]# ./configure --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'
[root@localhost nginx-1.22.0]# yum install -y openssl-devel
[root@localhost nginx-1.22.0]# ./configure --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'
(5)一直到這步,configure文件就執(zhí)行好了?
(6)make,make install編譯安裝
[root@localhost nginx-1.22.0]# make
[root@localhost nginx-1.22.0]# make install
[root@localhost nginx-1.22.0]# nginx -V
nginx version: nginx/1.22.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (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'
安裝完成?
三.nginx部分目錄結構
1.conf目錄
[root@localhost nginx-1.22.0]# ll
total 804
drwxr-xr-x 6 1001 1001 326 Aug 9 19:25 auto
-rw-r--r-- 1 1001 1001 317070 May 24 2022 CHANGES
-rw-r--r-- 1 1001 1001 484445 May 24 2022 CHANGES.ru
drwxr-xr-x 2 1001 1001 168 Aug 9 20:30 conf
-rwxr-xr-x 1 1001 1001 2590 May 24 2022 configure
drwxr-xr-x 4 1001 1001 72 Aug 9 19:25 contrib
drwxr-xr-x 2 1001 1001 40 Aug 9 19:25 html # Nginx 的默認站點目錄
-rw-r--r-- 1 1001 1001 1397 May 24 2022 LICENSE
-rw-r--r-- 1 root root 387 Aug 9 19:49 Makefile
drwxr-xr-x 2 1001 1001 21 Aug 9 19:25 man
drwxr-xr-x 3 root root 174 Aug 9 20:26 objs
-rw-r--r-- 1 1001 1001 49 May 24 2022 README
drwxr-xr-x 9 1001 1001 91 Aug 9 19:25 src[root@localhost nginx-1.22.0]# pwd
/usr/local/src/nginx-1.22.0[root@localhost nginx-1.22.0]# tree conf
conf
├── fastcgi.conf # fastcgi 相關參數的配置文件
├── fastcgi_params # fastcgi 的參數文件
├── koi-utf
├── koi-win
├── mime.types # 媒體類型
├── nginx.conf # Nginx默認的主配置文件
├── scgi_params
├── uwsgi_params
└── win-utf0 directories, 9 files
2.html目錄
[root@localhost nginx-1.22.0]# tree html
html
├── 50x.html # 錯誤頁面替代顯示文件,出現(xiàn)錯誤時調用這個頁面
└── index.html # 默認的首頁文件, 在實際環(huán)境中,一般用index.html、 index.php或index.jsp來做
?
四.nginx配置文件說明
[root@localhost ~]# vim /etc/nginx/nginx.conf #rpm包在這個文件,源碼安裝的配置文件是/usr/local/src/nginx-1.22.0/conf/nginx.conf
user nginx; #用戶
worker_processes auto; #主模塊命令,指定bnginx要開啟的進程數,一般指定一個,如果cpu多多和,則和cpu數量一致即可error_log /var/log/nginx/error.log notice; #主模塊命令,全局錯誤日志,debug(最詳細),info,notice,warn,error,crit(最簡略)
pid /var/run/nginx.pid; #主模塊命令,指定進程id的存儲文件位置#events指定設定nginx的工作模式和連接上限
events { #use 模式 (事件模塊指令,放在events中指定nginx的工作模式,select-標準工作模式,poll-標準工作模式,kqueue-BDS系統(tǒng)高效工作模式,epoll-Linux平臺首選高效工作模式,rtsig,/dev/poll)worker_connections 1024; #事件模塊指令,定義每個進程的最大連接數,默認1024,max_client客戶端連接數=worker_processes*worker_connections,max_clients=worker_processes*worker_connections/4,當然這些設置也受文件系統(tǒng)打開數量限制,執(zhí)行名“ulimit -n 65535”后生效
}#http服務配置
http {include /etc/nginx/mime.types; #include主模塊命令,include配置文件default_type application/octet-stream; #http核心模塊指令,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; #超時時間server { #server 區(qū)塊listen 80; #端口server_name localhost; #域名location / { #location區(qū)塊,可以寫多個root html; #站點目錄,路徑不定,按我的源碼安裝方式那就在/usr/local/src/nginx-1.22.0/htmlindex index.html index.htm; #首頁文件} error_page 500 502 503 504 /50x.html; #錯誤信息配置location = /50x.html { #html文件位置root html; #路徑}}#gzip on; #是否開啟壓縮
include /etc/nginx/conf.d/*.conf;
}