CentOS?7.6安裝與Nginx的配置文件詳解
注:wget https://www.openssl.org/source/openssl-1.1.1t.tar.gz 后面記得一定加上–no-check-certificate,不然要報(bào)錯(cuò)。顯示www.openssl.org上頒發(fā)的證書已經(jīng)過期無(wú)法驗(yàn)證,手動(dòng)狗頭。
報(bào)錯(cuò)圖片如下:
測(cè)試一下nginx,從別臺(tái)機(jī)器訪問一下服務(wù)器的IP,出現(xiàn)“Welcome to nginx!”頁(yè)面就說明成功了;如果訪問不到頁(yè)面但是可以ping通服務(wù)器的話可能是開啟了防火墻,關(guān)閉就行。關(guān)閉防火墻
關(guān)閉防火墻開機(jī)自啟
systemctl disable firewalld.service四、介紹一下Nginx命令啟動(dòng)nginx服務(wù)/usr/local/nginx/sbin/nginx重啟nginx服務(wù)/usr/local/nginx/sbin/nginx –s reload停止nginx服務(wù)/usr/local/nginx/sbin/nginx –s stop強(qiáng)制關(guān)閉nginx服務(wù)pkill nginx五、介紹一下Nginx的配置nginx.conf配置文件介紹#nginx配置#user nobody;worker_processes 1; #服務(wù)器并發(fā)處理服務(wù)關(guān)鍵配置#error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;#pidlogs/nginx.pid;events { worker_connections 1024; #最大連接數(shù)為 1024.}http { log_format main '$remote_addr - $remote_user [$time_local] '$request' ' '$status $body_bytes_sent '$http_referer' ' ''$http_user_agent' '$http_x_forwarded_for''; include mime.types; default_type application/octet-stream; sendfileon; tcp_nopush on; keepalive_timeout 65; #gzip on; #http頭壓縮 #正向代理配置 server { listen 8080; # 代理監(jiān)聽端口resolver 114.114.114.114; #代理DNS配置#charset koi8-r;access_log /home/lich/logs/fproxy.access.log; #accesslog輸出路徑error_log /home/lich/logs/fproxy.error.log; #errorlog輸出路徑location / { proxy_pass $scheme://$host$request_uri; # 配置正向代理參數(shù) proxy_set_header Host $http_host; # 解決如果URL中帶'.'后Nginx 503錯(cuò)誤 proxy_buffers 256 4k; # 配置緩存大小 proxy_max_temp_file_size 0; # 關(guān)閉磁盤緩存讀寫減少I/O proxy_connect_timeout 30; # 代理連接超時(shí)時(shí)間 # 配置代理服務(wù)器HTTP狀態(tài)緩存時(shí)間 proxy_cache_valid 200 302 10m; proxy_cache_valid 301 1h; proxy_cache_valid any 1m;} } #反向代理配置 server {listen 80;server_name test.test.com; #代理轉(zhuǎn)發(fā)域名配置access_log /home/lich/logs/rproxy.access.log;error_log /home/lich/logs/rproxy.error.log;location / { proxy_pass http://172.16.113.1:8001; #代理到后段實(shí)際應(yīng)用服務(wù)器地址 index index.html index.htm index.jsp;}#error_page 404 /404.html;# redirect server error pages to the static page /50x.htmlerror_page 500 502 503 504 /50x.html;location = /50x.html { root html;} }}監(jiān)聽配置用法listen *:80 | *:8080#監(jiān)聽所有80端口和8080端口listen IP_address:port #監(jiān)聽指定的地址和端口號(hào)listen IP_address #監(jiān)聽指定ip地址所有端口listen port #監(jiān)聽該端口的所有IP連接server_name:基于名稱的虛擬主機(jī)配置語(yǔ)法格式如下:# server_name name ...;對(duì)于name 來說,可以只有一個(gè)名稱,也可以有多個(gè)名稱,中間用空格隔開。而每個(gè)名字由兩段或者三段組成,每段之間用“.”隔開。server_name test.com www.test.com可以使用通配符“*”,但通配符只能用在由三段字符組成的首段或者尾端,或者由兩端字符組成的尾端。server_name *.test.com www.test.*還可以使用正則表達(dá)式,用“~”作為正則表達(dá)式字符串的開始標(biāo)記。server_name ~^www\d+\.test\.com$;server_name:基于IP地址的虛擬主機(jī)配置#語(yǔ)法結(jié)構(gòu)和基于域名匹配一樣,而且不需要考慮通配符和正則表達(dá)式的問題。
server_name 192.168.1.1proxy_pass該指令用于設(shè)置被代理服務(wù)器的地址。可以是主機(jī)名稱、IP地址加端口號(hào)的形式
# proxy_pass URL;# URL 為被代理服務(wù)器的地址,可以包含傳輸協(xié)議、主機(jī)名稱或IP地址加端口號(hào),URI等。proxy_pass http://www.test.com/uri;index該指令用于設(shè)置網(wǎng)站的默認(rèn)首頁(yè)。
#index filename ...;#后面的文件名稱可以有多個(gè),中間用空格隔開。index index.html index.jsp;六 ngxin負(fù)載均衡輪詢算法負(fù)載均衡upstream OrdinaryPolling { server 172.16.113.1:8081; server 172.16.113.1:8082;}server {listen 80; server_name test.test.com;access_log /home/lich/logs/rproxy_slb.access.log;error_log /home/lich/logs/rproxy_slb.error.log;location / { proxy_pass http://OrdinaryPolling; index index.html index.htm index.jsp; # deny ip # allow ip}}基于比例加權(quán)輪詢負(fù)載均衡upstream OrdinaryPolling { server 172.16.113.1:8081 weight=2; server 172.16.113.1:8082 weight=5;}server {listen 80; server_name test.test.com;access_log /home/lich/logs/rproxy_slb.access.log;error_log /home/lich/logs/rproxy_slb.error.log;location / { proxy_pass http://OrdinaryPolling; # index index.html index.htm index.jsp; # deny ip # allow ip}}基于IP路由負(fù)載均衡在 upstream 指令塊中增加了ip_hash 指令。該指令就是告訴 nginx 服務(wù)器,同一個(gè) IP 地址客戶端發(fā)送的請(qǐng)求都將分發(fā)到同一個(gè) Tomcat 服務(wù)器進(jìn)行處理。
upstream OrdinaryPolling { server 172.16.113.1:8081 weight=2; server 172.16.113.1:8082 weight=5; ip_hash;}server {listen 80; server_name test.test.com;access_log /home/lich/logs/rproxy_slb.access.log;error_log /home/lich/logs/rproxy_slb.error.log;location / { proxy_pass http://OrdinaryPolling; # index index.html index.htm index.jsp; # deny ip # allow ip}}基于服務(wù)器響應(yīng)時(shí)間負(fù)載均衡根據(jù)服務(wù)器處理請(qǐng)求的時(shí)間來進(jìn)行負(fù)載,處理請(qǐng)求越快,也就是響應(yīng)時(shí)間越短的優(yōu)先分配。
upstream OrdinaryPolling { server 172.16.113.1:8081 weight=2; server 172.16.113.1:8082 weight=5; fair;}server {listen 80; server_name test.test.com;access_log /home/lich/logs/rproxy_slb.access.log;error_log /home/lich/logs/rproxy_slb.error.log;location / { proxy_pass http://OrdinaryPolling; # index index.html index.htm index.jsp; # deny ip # allow ip}}到此這篇關(guān)于CentOS 7.6安裝Nginx及配置文件詳解的文章就介紹到這了,更多相關(guān)CentOS 7.6安裝Nginx及配置文件詳解內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. Windows?安裝?nginx?部署教程2. 一文帶你搞懂什么是Nginx服務(wù)器3. nginx ingress限速那些事淺析4. 完全卸載nginx以及安裝的超詳細(xì)步驟5. 網(wǎng)站如何通過nginx設(shè)置黑/白名單IP限制及國(guó)家城市IP訪問限制6. Nginx如何安裝配置Lua支持7. nginx有哪些常規(guī)調(diào)優(yōu)手段詳解8. nginx多l(xiāng)ocation配置實(shí)例代碼9. Nginx error_page自定義錯(cuò)誤頁(yè)面設(shè)置過程10. nginx進(jìn)行端口轉(zhuǎn)發(fā)的實(shí)現(xiàn)
