日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

centos8上安装nginx

發布時間:2023/12/3 编程问答 48 豆豆
生活随笔 收集整理的這篇文章主要介紹了 centos8上安装nginx 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

參考自 https://www.jianshu.com/p/9b2dd37a5af9? ;

【1】安裝步驟

step1)安裝nginx

sudo yum install -y nginx

step2)啟動nginx服務

-- 開機自啟動 sudo systemctl enable nginx -- 開啟nginx 服務 sudo systemctl start nginx

step3)查看nginx狀態

sudo systemctl status nginx

step4)查看本機ip地址

sudo hostname -I | awk '{print $1}'

如ip地址為 192.168.163.204 ;

step5)window機器上訪問? 192.168.163.204, 無法訪問;

step6)顯然防火墻關閉該端口被訪問權限,需要打開

sudo firewall-cmd --permanent --zone=public --add-service=http sudo firewall-cmd --permanent --zone=public --add-service=https sudo firewall-cmd --reload# 開通8080訪問權限 firewall-cmd --zone=public --add-port=8080/tcp --permanent# 重載防火墻配置 firewall-cmd --reload

step7)再次訪問成功

【2】nginx管理命令

  • 1)sudo systemctl status nginx : 查看nginx狀態;
  • 2)sudo systemctl stop nginx : 關閉nginx服務;
  • 3) sudo systemctl start nginx : 啟動或重啟 nginx服務;
  • 4) sudo systemctl reload nginx : 若修改了配置,如反向代理,重新加載配配置而不必重啟;
  • 5)sudo systemctl? disable nginx :禁止開機自啟動;
  • 6)sudo systemctl enable nginx? : 開機自啟動;?

【補充】nginx安裝完成后, 其配置文件在? /etc/nginx/nginx.conf?

[root@localhost nginx]# pwd /etc/nginx [root@localhost nginx]# ls conf.d fastcgi_params mime.types scgi_params win-utf default.d fastcgi_params.default mime.types.default scgi_params.default fastcgi.conf koi-utf nginx.conf uwsgi_params fastcgi.conf.default koi-win nginx.conf.default uwsgi_params.default

nginx可執行腳本在

[root@localhost sbin]# which nginx /usr/sbin/nginx

【3】nginx腳本命令

[root@localhost sbin]# nginx -v // 查看版本號 nginx version: nginx/1.14.1 [root@localhost sbin]# ps -ef | grep nginx // 查看nginx進程是否開啟 root 11913 1 0 22:21 ? 00:00:00 nginx: master process /usr/sbin/nginx nginx 11921 11913 0 22:21 ? 00:00:00 nginx: worker process nginx 11922 11913 0 22:21 ? 00:00:00 nginx: worker process root 11984 1511 0 22:34 pts/0 00:00:00 grep --color=auto nginx [root@localhost sbin]# [root@localhost sbin]# nginx -s stop // 關閉nginx 服務 [root@localhost sbin]# [root@localhost sbin]# ps -ef | grep nginx root 11991 1511 0 22:35 pts/0 00:00:00 grep --color=auto nginx [root@localhost sbin]# [root@localhost sbin]# [root@localhost sbin]# nginx // 啟動nginx 服務 [root@localhost sbin]# [root@localhost sbin]# ps -ef | grep nginx root 11993 1 0 22:35 ? 00:00:00 nginx: master process nginx nginx 11994 11993 0 22:35 ? 00:00:00 nginx: worker process nginx 11995 11993 0 22:35 ? 00:00:00 nginx: worker process root 11997 1511 0 22:35 pts/0 00:00:00 grep --color=auto nginx [root@localhost sbin]# [root@localhost sbin]# nginx -s reload // 重新加載nginx配置 [root@localhost sbin]# [root@localhost sbin]#

【4】nginx結構說明

1)所有Nginx配置文件都位于/etc/nginx/目錄中。
2)Nginx配置:主要配置文件是/etc/nginx/nginx.conf。為每個域創建一個單獨的配置文件使服務器易于維護。Nginx服務器阻止文件必須以結尾.conf并存儲在/etc/nginx/conf.d目錄中。您可以根據需要擁有任意數量的服務器塊。

[root@localhost local]# cd /etc/nginx/ [root@localhost nginx]# ls conf.d fastcgi_params.default nginx.conf uwsgi_params.default default.d koi-utf nginx.conf.default win-utf fastcgi.conf koi-win scgi_params fastcgi.conf.default mime.types scgi_params.default fastcgi_params mime.types.default uwsgi_params [root@localhost nginx]# ll total 68 drwxr-xr-x. 2 root root 6 Oct 7 2019 conf.d drwxr-xr-x. 2 root root 6 Oct 7 2019 default.d -rw-r--r--. 1 root root 1077 Oct 7 2019 fastcgi.conf -rw-r--r--. 1 root root 1077 Oct 7 2019 fastcgi.conf.default -rw-r--r--. 1 root root 1007 Oct 7 2019 fastcgi_params -rw-r--r--. 1 root root 1007 Oct 7 2019 fastcgi_params.default -rw-r--r--. 1 root root 2837 Oct 7 2019 koi-utf -rw-r--r--. 1 root root 2223 Oct 7 2019 koi-win -rw-r--r--. 1 root root 5170 Oct 7 2019 mime.types -rw-r--r--. 1 root root 5170 Oct 7 2019 mime.types.default -rw-r--r--. 1 root root 2469 Oct 7 2019 nginx.conf -rw-r--r--. 1 root root 2656 Oct 7 2019 nginx.conf.default -rw-r--r--. 1 root root 636 Oct 7 2019 scgi_params -rw-r--r--. 1 root root 636 Oct 7 2019 scgi_params.default -rw-r--r--. 1 root root 664 Oct 7 2019 uwsgi_params -rw-r--r--. 1 root root 664 Oct 7 2019 uwsgi_params.default -rw-r--r--. 1 root root 3610 Oct 7 2019 win-utf


3)遵循標準命名約定是一個好習慣。例如,如果域名是,mydomain.com則配置文件應命名為mydomain.com.conf;如果在域服務器塊中使用可重復的配置段,則最好將這些段重構為片段。
4)Nginx日志:日志文件(access.log和error.log)位于/var/log/nginx/目錄中。建議有不同access和error日志文件每個服務器模塊。
5)您可以將域文檔的根目錄設置為所需的任何位置。webroot的最常見位置包括:

  • /home/<user_name>/<site_name>? :
  • /var/www/<site_name>? : 存儲不同網站的資源 ;
  • /var/www/html/<site_name>? :存放靜態資源 html,css,js;
  • /opt/<site_name>? :
  • /usr/share/nginx/html? : 靜態html文件的位置;

總結

以上是生活随笔為你收集整理的centos8上安装nginx的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。