Centos7安裝ngnix方法和步驟

  • 添加資源庫

              在 CentOS 系統上安裝 Nginx ,你得先去添加一個資源庫,像這樣:vim /etc/yum.repos.d/nginx.repo

              使用 vim 命令去打開 /etc/yum.repos.d/nginx.repo ,如果 nginx.repo 不存在,就會去創建一個這樣的文件,打開以後按一下小 i 鍵,進入編輯模式,然後複製粘貼下面這幾行代碼,完成以後按 esc 鍵退出,再輸入:wq (保存並退出)

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

完成上邊操作以後,我們就可以使用 yum 命令去安裝 nginx 了

# yum install nginx

安裝成功:
測試nginx配置文件
當你執行 nginx -t 得時候,nginx會去測試你得配置文件得語法,並告訴你配置文件是否寫得正確,同時也告訴了你配置文件得路徑:

nginx –t


打印如下:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful


說明配置文件成功!
centos7.0+ nginx實現停止、啓動、重啓
在CentOS7中,進行chkconfig命令操作時會發現有類似“systemctl.....”的提示,systemctl可以簡單實現service和chkconfig的結合,這樣通過一個命令就可以實現兩個命令的功能。
systemctl命令的基本操作格式是:
systemctl [OPTIONS...] {COMMAND}...
以nginx服務爲例,實現停止、啓動、重啓的動作如下:

systemctl stop  nginx.service
systemctl start  nginx.service
systemctl restart nginx.service


檢查服務狀態

systemctl status nginx.service


使服務開機啓動

systemctl enable nginx.service

取消服務開機啓動

systemctl disable nginx.service

修改/etc/nginx/nginx.conf
   #user nginx;
   user  root;
worker_processes  1;
修改/etc/nginx/conf.d/default.conf

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
       # root   /usr/share/nginx/html;
        root   /wwwroot/images;
        index  index.html index.htm;
    }

    #error_page  404              /404.html;
    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
       # root   /usr/share/nginx/html;
         root   /wwwroot/images;
    }


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章