国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術(shù)文章
文章詳情頁

CentOS?7.6安裝與Nginx的配置文件詳解

瀏覽:3日期:2023-07-16 19:50:29
目錄一、安裝Nginx需要的環(huán)境庫二、安裝Ngnix三、啟動Nginx四、介紹一下Nginx命令五、介紹一下Nginx的配置六 ngxin負(fù)載均衡一、安裝Nginx需要的環(huán)境庫注:所有命令均在root權(quán)限下執(zhí)行項(xiàng)目首先我們需要安裝gcc、gcc-c++、zlib、pcre 和openssl。安裝gcc gcc-c++;yum install -y gcc gcc-c++下載安裝pcre; cd /usr/local/ wget http://downloads.sourceforge.net/project/pcre/pcre/8.45/pcre-8.45.tar.gz tar -zxvf pcre-8.45.tar.gz cd pcre-8.45 ./configure make && make install下載安裝openssl; cd /usr/local/ wget https://www.openssl.org/source/openssl-1.1.1t.tar.gz --no-check-certificate tar -zxvf openssl-1.1.1t.tar.gz cd openssl-1.1.1t ./config make && make install

注:wget https://www.openssl.org/source/openssl-1.1.1t.tar.gz 后面記得一定加上–no-check-certificate,不然要報(bào)錯(cuò)。顯示www.openssl.org上頒發(fā)的證書已經(jīng)過期無法驗(yàn)證,手動狗頭。

下載安裝zlib; cd /usr/local/ wget http://zlib.net/zlib-1.2.13.tar.gz tar -zxvf zlib-1.2.13.tar.gz cd zlib-1.2.13 ./configure make && make install二、安裝Ngnix下載安裝Nginx; cd /usr/local/ wget http://nginx.org/download/nginx-1.23.3.tar.gz tar -zxvf nginx-1.23.3.tar.gz cd nginx-1.23.3 ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/pcre-8.45 make && make install創(chuàng)建ssl的軟鏈接,不然啟動nginx會報(bào)錯(cuò);ln -s /usr/local/lib64/libssl.so.1.1 /usr/lib64/libssl.so.1.1ln -s /usr/local/lib64/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1

報(bào)錯(cuò)圖片如下:

三、啟動Nginx啟動nginx/usr/local/nginx/sbin/nginx

測試一下nginx,從別臺機(jī)器訪問一下服務(wù)器的IP,出現(xiàn)“Welcome to nginx!”頁面就說明成功了;如果訪問不到頁面但是可以ping通服務(wù)器的話可能是開啟了防火墻,關(guān)閉就行。關(guān)閉防火墻

systemctl stop firewalld.service

關(guān)閉防火墻開機(jī)自啟

systemctl disable firewalld.service四、介紹一下Nginx命令啟動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)聽指定的地址和端口號listen IP_address #監(jiān)聽指定ip地址所有端口listen port #監(jiān)聽該端口的所有IP連接server_name:基于名稱的虛擬主機(jī)配置語法格式如下:# server_name name ...;對于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ī)配置

#語法結(jié)構(gòu)和基于域名匹配一樣,而且不需要考慮通配符和正則表達(dá)式的問題。

server_name 192.168.1.1proxy_pass

該指令用于設(shè)置被代理服務(wù)器的地址。可以是主機(jī)名稱、IP地址加端口號的形式

# proxy_pass URL;# URL 為被代理服務(wù)器的地址,可以包含傳輸協(xié)議、主機(jī)名稱或IP地址加端口號,URI等。proxy_pass http://www.test.com/uri;index

該指令用于設(shè)置網(wǎng)站的默認(rèn)首頁。

#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ā)送的請求都將分發(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ù)器處理請求的時(shí)間來進(jìn)行負(fù)載,處理請求越快,也就是響應(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)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: IIS Windows
相關(guān)文章:
主站蜘蛛池模板: 建阳市| 黄陵县| 绵竹市| 丰都县| 喜德县| 中江县| 饶平县| 库尔勒市| 安溪县| 新龙县| 琼结县| 萨嘎县| 宣武区| 安康市| 巴楚县| 新龙县| 远安县| 新竹市| 石家庄市| 肥乡县| 沙洋县| 平遥县| 陆川县| 同心县| 霸州市| 徐州市| 全州县| 封开县| 神木县| 裕民县| 易门县| 苍梧县| 泗水县| 逊克县| 洪泽县| 邓州市| 彭水| 长宁县| 莱芜市| 江孜县| 鄂温|