服务器CentOS 8.0+安装nginx

  1. 切换服务器操作系统CentOS 8.0+
  2. 安全组(选择下面两条)
    1. Sys-WebServer
    2. Sys-default
  3. ssh root@主机号登陆进去
  4.  
    cd / (cd到根目录)
  5. (安装nginx)
    yum install -y nginx
  6. cd /etc/nginx (可以通过ls查看该文件夹下里的文件和文件夹)
  7. ls (查看一下nginx)
  8. vi nginx.conf(编辑nginx.conf)
  9. 把红框的内容注释掉,最下边一行添加 
    include vhost/8.conf
  10. 在nginx下创建一个vhost文件夹(mkdir vhost)  
  11. cd vhost
  12. vi ysr.bdplus.cn.conf(创建一个.conf文件)
  13. #upstream goserver {                                                         
     #   server 127.0.0.1:9000;
    #}
    server {
        listen 80;
        server_name ysr.bdplus.cn;(自己的域名)
     #   return  301 https://$server_name$request_uri;
    #}
    #server{
     #   listen 443 ssl;
      #  server_name  api.bdplus.cn;
        root   /home/www/ysr.bdplus.cn;(内容文件夹地址)
    
        #ssl on;
       # ssl_certificate   /data/sys/cert/1531404801208/1531404801208.pem;
       # ssl_certificate_key  /data/sys/cert/1531404801208/1531404801208.key;
       # ssl_session_timeout 5m;
       # ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
       # ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
       # ssl_prefer_server_ciphers on;
    
    #    location / {
     #       index  index.php index.html index.htm;
      #  }
    #location / {
     #       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     #       proxy_set_header Host $http_host;
     #       proxy_redirect off;
    #        proxy_pass http://goserver;
     #   }
       # location ^~/api/{
       #rewrite ^/api/(.*)/$1 break;
       #proxy_pass http://api.bdplus.cn/api/;
    #}
    # location ^~/home/{
     #  rewrite ^/home/(.*)/$1 break;
     #  proxy_pass https://home-api.pinduoduo.com/home/;
    #}
    location /{
       try_files $uri /index.html;
       index index.html index.htm index.php;
    }
        location ~ /\. {
                return 403;
        }
        access_log  /data/log/www/ysr.bdplus.cn;(日志文件夹地址)
    }      
  14. 启动nginx
    systemctl start nginx.service
  15. 设置开机启动
    systemctl enable nginx.service
  16. 关闭nginx
    systemctl stop nginx.service
  17. 重启nginx
    systemctl restart nginx.service

     

posted @ 2021-07-01 20:03  Y冒泡泡~  阅读(112)  评论(0)    收藏  举报