nginx安裝以及安裝過程所遇到的問題

【安裝本地yum源或者臨時yum源】

安裝臨時yum源
第一步:安裝HTTP服務

# yum -y install httpd.x86_64


第二步:啓動服務,並設置httpd服務 開機自啓,


# systemctl status httpd
# systemctl start httpd
# systemctl enable httpd


第三步:讓httpd服務管理的目錄/var/www/html下有掛載的路徑的軟連接


# ln -s /mnt/dvd /var/www/html/repo


第四步:其他機器進行修改yum源配置文件


# cd /etc/yum.repos.d/
# rename .repo .repo.bak  ./*.repo
# cp CentOS-Base.repo.bak local.repo
# vi local.repo
[local]     						
name=local		  					
baseurl=http://qianfeng01/repo		
enabled=1							
gpgcheck=1							
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7  


1)yum info nginx
找不到nginx的安裝包
2)rpm -ivh https://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-
centos-7-0.el7.ngx.noarch.rpm
(要能夠連接外網)

【ping www.baidu.com 】

查看 ifcfg-eth0下的ip和網關地址 是否是在DHCP設置的範圍內

解決方法

     

1.恢復VMware的網絡默認設置
  編輯->虛擬網絡編輯器

2.還原默認設置 
並且查看nat模式下的NAT設置
    記住網關地址 
查看NAt模式下的DHCP設置
     記住ip範圍

3.vi /etc/sysconfig/network-scripts/ifcfg-ens33
修改虛擬機ip地址和網關


3).yum repolist 發現yum源中,多了個nginx cd /etc/yum.repo.d
4).安裝nginx:yum -y install nginx ##(要能夠連接外網)

錯誤:軟件包:nginx-1.18.0-1.el6.ngx.x86_64 (nginx)
          需要:libpcre.so.0()(64bit)
 您可以嘗試添加 --skip-broken 選項來解決該問題
 您可以嘗試執行:rpm -Va --nofiles --nodigest

解決辦法:(6改爲7)

 vi /etc/yum.repos.d/nginx.repo

# nginx.repo



[nginx]

name=nginx repo

baseurl=http://nginx.org/packages/centos/7/$basearch/

gpgcheck=0

enabled=1


5).service nginx start
ps:查看nginx安裝目錄 whereis nginx

【啓動失敗

Redirecting to /bin/systemctl start nginx.service
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.

netstat -nltp

端口80 被佔用

殺死進程或者修改nginx的端口號


6).查看http://192.168.XXX.XXX:80如果可以看到nginx的頁面就表示你已經配置ok了


7).配置下nginx

nginx的配置目錄
cd /etc/nginx/
vi /etc/nginx/nginx.conf

vi /etc/ngnx/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;
        index  index.html index.htm;
    }

vi /etc/nginx/nginx.conf  自定義配置文件

user  root;    //root用戶
worker_processes  1;    //工作進程數

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;    //進程號


events {
    worker_connections  1024;  //連接數 併發數量
}


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

    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;

    keepalive_timeout  65;

    #gzip  on;

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

 

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