使用Yum安裝是推薦的方式,整體的流程非常的簡(jiǎn)單,也不容易出錯(cuò),如果不需要什么特殊配置,建議使用Yum盡進(jìn)行安裝。
1、安裝epel-release源并進(jìn)行安裝
| 123 | yuminstall epel-releaseyum updateyuminstall nginx |
2、執(zhí)行相關(guān)的應(yīng)用操作
| 12345 | systemctlstart nginx#啟動(dòng)systemctl stop nginx#停止systemctlrestart nginx#重啟systemctl status nginx#查看運(yùn)行狀態(tài)systemctlenable nginx#開機(jī)啟動(dòng) |
3、設(shè)置防火墻
在啟動(dòng)完以后可能無法通過ip訪問,需要進(jìn)一步設(shè)置防火墻(關(guān)于firewall-cmd的使用方法下一篇文章再詳細(xì)講解)
| 123 | firewall-cmd--permanent--zone=public--add-service=httpfirewall-cmd--permanent--zone=public--add-service=httpsfirewall-cmd--reload |
至此,安裝完畢。
參考文章:https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-centos-7
1、安裝編譯所需工具
| 12 | yumgroupinstall "Development Tools"yum install wget |
2、到官網(wǎng)下載最新的源代碼(https://nginx.org/en/)
| 123 | cd/usr/local/srcwget http://nginx.org/download/nginx-1.10.2.tar.gztarzxvf nginx-1.10.2.tar.gz |
3、安裝依賴包
| 1 | yuminstall zlib zlib-developenssl openssl-develpcre pcre-devel |
4、創(chuàng)建用來運(yùn)行nginx的用戶及組
| 12 | groupaddnginxuseradd -gnginx -Mnginx –s/sbin/nologin |
-g參數(shù)為nginx用戶指定了一個(gè)組。-M參數(shù)保證其不自動(dòng)生成home目錄。
5、編譯源代碼
先使用./configure –help 查看編譯幫助:
| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 | [root@localhostnginx-1.10.2]# ./configure --help --help PRint thismessage --prefix=PATH setinstallation prefix#Nginx安裝的根路徑,默認(rèn)為 /usr/local/nginx。 --sbin-path=PATH set nginx binarypathname #指定nginx二進(jìn)制文件的路徑,默認(rèn)為PATH/sbin/nginx。 --modules-path=PATH setmodules path#Perl模塊位置 --conf-path=PATH set nginx.confpathname #設(shè)定nginx配置文件地址,默認(rèn)為PATH/conf/nginx.conf。 --error-log-path=PATH seterror log pathname#錯(cuò)誤文件路徑,默認(rèn)為 PATH/logs/error.log。 --pid-path=PATH setnginx.pidpathname # master進(jìn)程pid寫入的文件位置,通常在var/run下,默認(rèn)為 PATH/logs/nginx.pid。 --lock-path=PATH set nginx.lockpathname #共享存儲(chǔ)器互斥鎖文件路徑 --user=USER setnon-privilegeduser forworker processes#指定程序運(yùn)行時(shí)的非特權(quán)用戶 --group=GROUP setnon-privilegedgroup forworker processes#指定程序運(yùn)行時(shí)的非特權(quán)用戶組 --build=NAME set build name#編譯名稱 --builddir=DIR set build directory#指向編譯目錄 --with-select_module enable select module 允許或不允許開啟SELECT模式,如果configure沒有找到合適的模式,比如,kqueue(sunos)、epoll(linuxkenel 2.6+)、rtsig(實(shí)時(shí)信號(hào)) --without-select_module disableselect module禁用select模塊支持 --with-poll_module enable poll module啟用poll模塊支持(功能與select相同,與select特性相同,為一種輪詢模式,不推薦在高載環(huán)境下使用) --without-poll_module disablepoll module禁用poll模塊支持 --with-threads enable thread pool support --with-file-aio enablefile AIO support#為freeBSD4.3+和linux2.6.22+系統(tǒng)啟用異步io --with-ipv6 enableIPv6 support#啟用ipv6支持 #默認(rèn)禁用的模塊 --with-http_ssl_module enable ngx_http_ssl_module#使支持https請(qǐng)求,需已安裝openssl --with-http_v2_module enablengx_http_v2_module #啟用HTTP V2 --with-http_realip_module enablengx_http_realip_module#此模塊支持顯示真實(shí)來源IP地址,主要用于NGINX做前端負(fù)載均衡服務(wù)器使用 --with-http_addition_module enablengx_http_addition_module#輸出過濾器,使你能夠在請(qǐng)求經(jīng)過一個(gè)location前或后時(shí)在該location本身添加內(nèi)容 --with-http_xslt_module enablengx_http_xslt_module #這個(gè)模塊是一個(gè)過濾器,它可以通過XSLT模板轉(zhuǎn)換xml應(yīng)答 --with-http_xslt_module=dynamic enabledynamic ngx_http_xslt_module --with-http_image_filter_module enablengx_http_image_filter_module#圖像過濾器,在將圖像投遞到客戶之前進(jìn)行處理(需要libgd庫) --with-http_image_filter_module=dynamic enable dynamic ngx_http_image_filter_module --with-http_geoip_module enable ngx_http_geoip_module#創(chuàng)建基于與MaxMind GeoIP相配的客戶端地址 --with-http_geoip_module=dynamic enable dynamic ngx_http_geoip_module --with-http_sub_module enable ngx_http_sub_module#這個(gè)模塊可以能夠在nginx的應(yīng)答中搜索并替換文本 --with-http_dav_module enable ngx_http_dav_module#為文件和目錄指定權(quán)限,限制不同類型的用戶對(duì)于頁面有不同的操作權(quán)限 --with-http_flv_module enable ngx_http_flv_module#這個(gè)模塊支持對(duì)FLV(Flash)文件的拖動(dòng)播放 --with-http_mp4_module enable ngx_http_mp4_module#支持H.264/AAC文件為偽流媒體 --with-http_gunzip_module enablengx_http_gunzip_module#對(duì)于不支持gzip編碼的客戶,該模塊用于為客戶解壓縮預(yù)壓縮內(nèi)容 --with-http_gzip_static_module enable ngx_http_gzip_static_module#這個(gè)模塊在一個(gè)預(yù)壓縮文件傳送到開啟Gzip壓縮的客戶端之前檢查是否已經(jīng)存在以“.gz”結(jié)尾的壓縮文件,這樣可以防止文件被重復(fù)壓縮 --with-http_auth_request_module enablengx_http_auth_request_module --with-http_random_index_module enablengx_http_random_index_module#從目錄中選擇一個(gè)隨機(jī)主頁 --with-http_secure_link_module enable ngx_http_secure_link_module#該模塊提供一種機(jī)制,它會(huì)將一個(gè)哈希值鏈接到一個(gè)url中,因此,只有那些使用正確的密碼能夠計(jì)算鏈接 --with-http_degradation_module enable ngx_http_degradation_module#允許在內(nèi)存不足的情況下返回204或444碼 --with-http_slice_module enable ngx_http_slice_module --with-http_stub_status_module enable ngx_http_stub_status_module#取得一些nginx的運(yùn)行狀態(tài),輸出的狀態(tài)信息可使用RRDtool或類似的工具繪制成圖#默認(rèn)啟用的模塊 --without-http_charset_module disablengx_http_charset_module#重新編碼web頁面 --without-http_gzip_module disable ngx_http_gzip_module#同-with-http_gzip_static_module功能一樣 --without-http_ssi_module disablengx_http_ssi_module #提供在輸入端處理處理服務(wù)器包含文件(SSI)的過濾器,目前支持SSI命令的列表是不完整的 --without-http_userid_module disable ngx_http_userid_module#用來處理用來確定客戶端后續(xù)請(qǐng)求的cookies --without-http_access_module disable ngx_http_access_module#供了一個(gè)簡(jiǎn)單的基于主機(jī)的訪問控制。允許/拒絕基于ip地址 --without-http_auth_basic_module disable ngx_http_auth_basic_module#可以使用用戶名和密碼基于http基本認(rèn)證方法來保護(hù)你的站點(diǎn)或其部分內(nèi)容 --without-http_autoindex_module disablengx_http_autoindex_module#自動(dòng)生成目錄列表,只在ngx_http_index_module模塊未找到索引文件時(shí)發(fā)出請(qǐng)求。 --without-http_geo_module disablengx_http_geo_module #創(chuàng)建一些變量,其值依賴于客戶端的IP地址 --without-http_map_module disablengx_http_map_module #使用任意的鍵/值對(duì)設(shè)置配置變量 --without-http_split_clients_moduledisable ngx_http_split_clients_module#用來基于某些條件劃分用戶。條件如:ip地址、報(bào)頭、cookies等等 --without-http_referer_module disablengx_http_referer_module#用來過濾請(qǐng)求,拒絕報(bào)頭中Referer值不正確的請(qǐng)求 --without-http_rewrite_module disablengx_http_rewrite_module#允許使用正則表達(dá)式改變URI,并且根據(jù)變量來轉(zhuǎn)向以及選擇配置 --without-http_proxy_module disablengx_http_proxy_module#有關(guān)代理服務(wù)器 --without-http_fastcgi_module disablengx_http_fastcgi_module#允許Nginx 與FastCGI 進(jìn)程交互,并通過傳遞參數(shù)來控制FastCGI 進(jìn)程工作。 --without-http_uwsgi_module disablengx_http_uwsgi_module#用來使用uwsgi協(xié)議,uWSGI服務(wù)器相關(guān) --without-http_scgi_module disable ngx_http_scgi_module#用來啟用SCGI協(xié)議支持,SCGI協(xié)議是CGI協(xié)議的替代。 --without-http_memcached_module disablengx_http_memcached_module#用來提供簡(jiǎn)單的緩存,以提高系統(tǒng)效率 --without-http_limit_conn_module disable ngx_http_limit_conn_module#允許你對(duì)于一個(gè)地址進(jìn)行連接數(shù)的限制用一個(gè)給定的session或一個(gè)特定的事件 --without-http_limit_req_module disablengx_http_limit_req_module#允許你對(duì)于一個(gè)地址進(jìn)行請(qǐng)求數(shù)量的限制用一個(gè)給定的session或一個(gè)特定的事件 --without-http_empty_gif_module disablengx_http_empty_gif_module#在內(nèi)存中常駐了一個(gè)1*1的透明GIF圖像,可以被非常快速的調(diào)用 --without-http_browser_module disablengx_http_browser_module#用來創(chuàng)建依賴于請(qǐng)求報(bào)頭的值 --without-http_upstream_hash_module disable ngx_http_upstream_hash_module#用于簡(jiǎn)單的負(fù)載均衡 --without-http_upstream_ip_hash_module disable ngx_http_upstream_ip_hash_module --without-http_upstream_least_conn_module disable ngx_http_upstream_least_conn_module --without-http_upstream_keepalive_module disable ngx_http_upstream_keepalive_module --without-http_upstream_zone_module disable ngx_http_upstream_zone_module --with-http_perl_module enablengx_http_perl_module #這個(gè)模塊允許nginx使用SSI調(diào)用perl或直接執(zhí)行perl(使用會(huì)降低性能) --with-http_perl_module=dynamic enabledynamic ngx_http_perl_module --with-perl_modules_path=PATH setPerl modules path#設(shè)定perl模塊路徑 --with-perl=PATH set perl binarypathname #設(shè)定perl庫文件路徑 --http-log-path=PATH set http accesslog pathname#設(shè)定access log路徑 --http-client-body-temp-path=PATH setpath tostore http clientrequest body temporaryfiles #設(shè)定http客戶端請(qǐng)求臨時(shí)文件路徑 --http-proxy-temp-path=PATH setpath tostore http proxytemporary files#設(shè)定http代理臨時(shí)文件路徑 --http-fastcgi-temp-path=PATH setpath tostore http fastcgitemporary files#設(shè)定http fastcgi臨時(shí)文件路徑 --http-uwsgi-temp-path=PATH setpath tostore http uwsgitemporary files#設(shè)定http uwsgi臨時(shí)文件路徑 --http-scgi-temp-path=PATH set path tostore http scgitemporary files#設(shè)定http scgi臨時(shí)文件路徑 --without-http disable HTTP server#完全禁用http模塊,如果只想支持mall,可以使用此項(xiàng)設(shè)置 --without-http-cache disable HTTP cache#在使用upstream模塊時(shí),nginx能夠配置本地緩存內(nèi)容,此選項(xiàng)可禁用緩存 --with-mail enablePOP3/IMAP4/SMTPproxy module#激活POP3/IMAP4/SMTP代理模塊,默認(rèn)未激活 --with-mail=dynamic enabledynamic POP3/IMAP4/SMTPproxy module --with-mail_ssl_module enable ngx_mail_ssl_module#SMTP可以使用SSL/TLS.配置已經(jīng)定義了HTTP SSL模塊,但是不支持客戶端證書檢測(cè) --without-mail_pop3_module disable ngx_mail_pop3_module#啟用mail模塊后,單獨(dú)禁用pop3模塊 --without-mail_imap_module disable ngx_mail_imap_module#啟用mail模塊后,單獨(dú)禁用imap模塊 --without-mail_smtp_module disable ngx_mail_smtp_module#啟用mail模塊后,單獨(dú)禁用smtp模塊 --with-stream enableTCP/UDPproxy module --with-stream=dynamic enabledynamic TCP/UDPproxy module --with-stream_ssl_module enable ngx_stream_ssl_module --without-stream_limit_conn_moduledisable ngx_stream_limit_conn_module --without-stream_access_module disable ngx_stream_access_module --without-stream_upstream_hash_module disable ngx_stream_upstream_hash_module --without-stream_upstream_least_conn_module disable ngx_stream_upstream_least_conn_module --without-stream_upstream_zone_module disable ngx_stream_upstream_zone_module --with-google_perftools_module enable ngx_google_perftools_module#調(diào)試用,剖析程序性能瓶頸 --with-cpp_test_module enable ngx_cpp_test_module --add-module=PATH enableexternal module#啟用外部模塊支持 --add-dynamic-module=PATH enabledynamic external module#編譯相關(guān)的參數(shù) --with-cc=PATH set Ccompiler pathname#如果想設(shè)置一個(gè)不在默認(rèn)path下的c編譯器 --with-cpp=PATH setC preprocessorpathname #設(shè)置c預(yù)處理器的相對(duì)路徑 --with-cc-opt=OPTIONS setadditional Ccompiler options#設(shè)置C編譯器參數(shù) --with-ld-opt=OPTIONS setadditional linker options #包含連接庫的路徑和運(yùn)行路徑 --with-cpu-opt=CPU build forthe specified CPU,valid values:pentium,pentiumpro,pentium3,pentium4,athlon,opteron,sparc32,sparc64,ppc64 #指定編譯的CPU --without-pcre disable PCRE libraryusage #禁用pcre庫 --with-pcre forcePCRE library usage#啟用pcre庫 --with-pcre=DIR setpath toPCRE library sources#指向pcre庫文件目錄 --with-pcre-opt=OPTIONS setadditional build options forPCRE #在編譯時(shí)為pcre庫設(shè)置附加參數(shù) --with-pcre-jit buildPCRE with JITcompilation support --with-md5=DIR set path tomd5 library sources#指向md5庫文件目錄 --with-md5-opt=OPTIONS set additional build options formd5 #在編譯時(shí)為md5庫設(shè)置附加參數(shù) --with-md5-asm use md5assembler sources#使用md5匯編源 --with-sha1=DIR setpath tosha1 library sources#指向sha1庫目錄 --with-sha1-opt=OPTIONS setadditional build options forsha1 #在編譯時(shí)為sha1庫設(shè)置附加參數(shù) --with-sha1-asm usesha1 assembler sources #使用sha1匯編源 --with-zlib=DIR setpath tozlib library sources#指向zlib庫目錄 --with-zlib-opt=OPTIONS setadditional build options forzlib #在編譯時(shí)為zlib設(shè)置附加參數(shù) --with-zlib-asm=CPU usezlib assembler sources optimized forthe specified CPU,valid values:pentium,pentiumpro #為指定的CPU使用zlib匯編源進(jìn)行優(yōu)化 --with-libatomic force libatomic_ops library usage# 為原子內(nèi)存的更新操作的實(shí)現(xiàn)提供一個(gè)架構(gòu) --with-libatomic=DIR set path tolibatomic_ops librarysources #指向libatomic_ops安裝目錄 --with-openssl=DIR set path toOpenSSL library sources #指向openssl安裝目錄 --with-openssl-opt=OPTIONS set additional build options forOpenSSL #在編譯時(shí)為openssl設(shè)置附加參數(shù) --with-debug enable debug logging#啟用debug日志 |
設(shè)置編譯參數(shù):
| 1234567891011121314151617181920212223 | ./configure/--prefix=/usr/local/nginx/--sbin-path=/usr/sbin/nginx/--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/--user=nginx/--group=nginx/--with-http_ssl_module/--with-pcre/--with-http_v2_module/--with-http_realip_module/--with-http_addition_module/--with-http_sub_module/--with-http_dav_module/--with-http_gunzip_module/--with-http_gzip_static_module/--with-http_random_index_module/--with-http_secure_link_module/--with-http_stub_status_module/--with-http_auth_request_module |
然后執(zhí)行make&& makeinstall 完成安裝后在 centos7 中為nginx的啟動(dòng)、重啟、重載配置添加腳本:
| 1 | vi/usr/lib/systemd/system/nginx |
添加內(nèi)容:
| 12345678910111213141516 | [Unit]Description=nginx- highperformance web serverDocumentation=http://nginx.org/en/docs/After=network.targetremote-fs.targetnss-lookup.target [Service]Type=forkingPIDFile=/var/run/nginx.pidExecStartPre=/usr/sbin/nginx-t-c/etc/nginx/nginx.confExecStart=/usr/sbin/nginx-c/etc/nginx/nginx.confExecReload=/bin/kill-sHUP $MAINPIDExecStop=/bin/kill-sQUIT $MAINPIDPrivateTmp=true [Install]WantedBy=multi-user.target |
相關(guān)操作:
| 123456789 | systemctlis-enablednginx.service#查詢nginx是否開機(jī)啟動(dòng)systemctl enable nginx.service#開機(jī)運(yùn)行nginxsystemctldisable nginx.service#取消開機(jī)運(yùn)行nginxsystemctl start nginx.service#啟動(dòng)nginxsystemctlstop nginx.service#停止nginxsystemctl restart nginx.service#重啟nginxsystemctlreload nginx.service#重新加載nginx配置文件systemctl status nginx.service#查詢nginx運(yùn)行狀態(tài)systemctl--failed#顯示啟動(dòng)失敗的服務(wù) |
其他配置盡情期待另外的文章。
原文鏈接:http://www.biaodianfu.com/centos-7-2-install-nginx-1-10-2.html
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注