搜尋
首頁運維NginxRHEL8中怎麼部署Nginx Web服務

RHEL8中怎麼部署Nginx Web服務

May 14, 2023 pm 10:31 PM
webnginxrhel

RHEL8中怎么部署Nginx Web服务

環境

Red Hat Enterprise Linux release 8.0 VMware Workstation Pro 14

#建置步驟

[root@localhost ~]# systemctl stop httpd  #把 httpd 停掉,防止它影响 Nginx[root@localhost ~]# yum install -y nginx[root@localhost ~]# systemctl start nginx[root@localhost ~]# iptables -F[root@localhost ~]# systemctl stop firewalld[root@localhost ~]# systemctl disable firewalld[root@localhost ~]# setenforce 0[root@localhost ~]# ifconfigens33: flags=4163  mtu 1500
       inet 192.168.10.118  netmask 255.255.255.0  broadcast 192.168.10.255
       inet6 fe80::e09a:769b:83f0:8efa  prefixlen 64  scopeid 0x20
       ether 00:50:56:34:0d:74  txqueuelen 1000  (Ethernet)
       RX packets 2908  bytes 1777392 (1.6 MiB)
       RX errors 0  dropped 0  overruns 0  frame 0
       TX packets 1800  bytes 244006 (238.2 KiB)
       TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73  mtu 65536
       inet 127.0.0.1  netmask 255.0.0.0
       inet6 ::1  prefixlen 128  scopeid 0x10
       loop  txqueuelen 1000  (Local Loopback)
       RX packets 0  bytes 0 (0.0 B)
       RX errors 0  dropped 0  overruns 0  frame 0
       TX packets 0  bytes 0 (0.0 B)
       TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099  mtu 1500
       inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
       ether 52:54:00:9c:ef:c6  txqueuelen 1000  (Ethernet)
       RX packets 0  bytes 0 (0.0 B)
       RX errors 0  dropped 0  overruns 0  frame 0
       TX packets 0  bytes 0 (0.0 B)
       TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

在瀏覽器輸入192.168.10.118 查看Nginx Web 伺服器的狀態

RHEL8中怎么部署Nginx Web服务

查看nginx 軟體套件的檔案清單

[root@localhost ~]# rpm -ql nginx/etc/logrotate.d/nginx
/etc/nginx/fastcgi.conf
/etc/nginx/fastcgi.conf.default
/etc/nginx/fastcgi_params
/etc/nginx/fastcgi_params.default
/etc/nginx/koi-utf
/etc/nginx/koi-win
/etc/nginx/mime.types
/etc/nginx/mime.types.default
/etc/nginx/nginx.conf
/etc/nginx/nginx.conf.default
...省略部分内容...

自訂首頁內容

RHEL8中怎么部署Nginx Web服务
#
[root@localhost ~]# echo "HLLO RHEL8" > /usr/share/nginx/html/index.html[root@localhost ~]# systemctl restart nginx

在瀏覽器輸入192.168.10.118 查看

#設定檔案共用服務

[root@localhost ~]# mv /usr/share/nginx/html/* /var/lib/nginx/tmp/[root@localhost ~]# touch /usr/share/nginx/html/file{1..10}[root@localhost ~]# ls /usr/share/nginx/html/file1  file10  file2  file3  file4  file5  file6  file7  file8  file9
[root@localhost ~]# systemctl restart nginx
RHEL8中怎么部署Nginx Web服务
RHEL 8 建置Nginx Web 服務RHEL 8 建置Nginx Web 服務
## 遇上403 Forbidden 報錯,原因是設定檔案沒配好,解決方法如下:

[root@localhost html]# grep -v "#" /etc/nginx/nginx.confuser nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

include /usr/share/nginx/modules/*.conf;

events {
   worker_connections 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"';

   access_log  /var/log/nginx/access.log  main;

   sendfile            on;
   tcp_nopush          on;
   tcp_nodelay         on;
   keepalive_timeout   65;
   types_hash_max_size 2048;

   include             /etc/nginx/mime.types;
   default_type        application/octet-stream;

   include /etc/nginx/conf.d/*.conf;

   server {
       listen       80 default_server;
       listen       [::]:80 default_server;
       server_name  localhost;
       root         /usr/share/nginx/html;

       include /etc/nginx/default.d/*.conf;

 
       location / {
            index  index.html index.htm;
            autoindex on;
            autoindex_exact_size on;
            autoindex_localtime on;
            charset utf-8;
            }
        }

}

參考以上設定進行修改

[root@localhost ~]# vim /etc/nginx/nginx.conf[root@localhost ~]# systemctl restart nginx

在瀏覽器輸入192.168.10.118 查看檔案共用狀態

RHEL8中怎么部署Nginx Web服务

設定連接埠對映

 RHEL8中怎么部署Nginx Web服务

查看宿主機IP

RHEL8中怎么部署Nginx Web服务
在瀏覽器輸入192.168.0.7:118 測試檔案共用服務狀態

RHEL8中怎么部署Nginx Web服务

在RHEL8 上用yum 安裝的Nginx Web 服務對中文的支援比較好

RHEL8中怎么部署Nginx Web服务
[root@localhost ~]# touch /usr/share/nginx/html/你好红帽8.txt[root@localhost ~]# systemctl restart nginx
#

以上是RHEL8中怎麼部署Nginx Web服務的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述
本文轉載於:亿速云。如有侵權,請聯絡admin@php.cn刪除
Nginx vs. Apache:看他們的架構Nginx vs. Apache:看他們的架構Apr 28, 2025 am 12:13 AM

NGINX和Apache在架構上的主要區別在於:NGINX採用事件驅動、異步非阻塞模型,而Apache使用進程或線程模型。 1)NGINX通過事件循環和I/O多路復用機制高效處理高並發連接,適合靜態內容和反向代理。 2)Apache採用多進程或多線程模型,穩定性高但資源消耗大,適合需要豐富模塊擴展的場景。

NGINX與Apache:檢查優點和缺點NGINX與Apache:檢查優點和缺點Apr 27, 2025 am 12:05 AM

NGINX適合處理高並發和靜態內容,Apache則適用於復雜配置和動態內容。 1.NGINX高效處理並發連接,適合高流量場景,但處理動態內容需額外配置。 2.Apache提供豐富模塊和靈活配置,適合複雜需求,但高並發性能較差。

nginx和apache:了解關鍵差異nginx和apache:了解關鍵差異Apr 26, 2025 am 12:01 AM

NGINX和Apache各有優劣,選擇應基於具體需求。 1.NGINX適合高並發場景,因其異步非阻塞架構。 2.Apache適用於需要復雜配置的低並發場景,因其模塊化設計。

NGINX單元:關鍵功能NGINX單元:關鍵功能Apr 25, 2025 am 12:17 AM

NGINXUnit是一個開源應用服務器,支持多種編程語言,提供動態配置、零停機更新和內置負載均衡等功能。 1.動態配置:無需重啟即可修改配置。 2.多語言支持:兼容Python、Go、Java、PHP等。 3.零停機更新:支持不中斷服務的應用更新。 4.內置負載均衡:可將請求分發到多個應用實例。

NGINX單元與其他應用程序服務器NGINX單元與其他應用程序服務器Apr 24, 2025 am 12:14 AM

NGINXUnit優於ApacheTomcat、Gunicorn和Node.js內置HTTP服務器,適用於多語言項目和動態配置需求。 1)支持多種編程語言,2)提供動態配置重載,3)內置負載均衡功能,適合需要高擴展性和可靠性的項目。

NGINX單元:架構及其工作原理NGINX單元:架構及其工作原理Apr 23, 2025 am 12:18 AM

NGINXUnit通過其模塊化架構和動態重配置功能提高了應用的性能和可管理性。 1)模塊化設計包括主控進程、路由器和應用進程,支持高效管理和擴展。 2)動態重配置允許在運行時無縫更新配置,適用於CI/CD環境。 3)多語言支持通過動態加載語言運行時實現,提升了開發靈活性。 4)高性能通過事件驅動模型和異步I/O實現,即使在高並發下也保持高效。 5)安全性通過隔離應用進程提高,減少應用間相互影響。

使用NGINX單元:部署和管理應用程序使用NGINX單元:部署和管理應用程序Apr 22, 2025 am 12:06 AM

NGINXUnit可用於部署和管理多種語言的應用。 1)安裝NGINXUnit。 2)配置它以運行不同類型的應用,如Python和PHP。 3)利用其動態配置功能進行應用管理。通過這些步驟,你可以高效地部署和管理應用,提升項目效率。

NGINX與Apache:Web服務器的比較分析NGINX與Apache:Web服務器的比較分析Apr 21, 2025 am 12:08 AM

NGINX更适合处理高并发连接,而Apache更适合需要复杂配置和模块扩展的场景。1.NGINX以高性能和低资源消耗著称,适合高并发。2.Apache以稳定性和丰富的模块扩展闻名,适合复杂配置需求。

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

mPDF

mPDF

mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

WebStorm Mac版

WebStorm Mac版

好用的JavaScript開發工具

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

將Eclipse與SAP NetWeaver應用伺服器整合。

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

VSCode Windows 64位元 下載

VSCode Windows 64位元 下載

微軟推出的免費、功能強大的一款IDE編輯器