伺服器CentOS 8.0+安裝nginx
阿新 • • 發佈:2021-07-01
- 切換伺服器作業系統CentOS 8.0+
-
安全組(選擇下面兩條)
- Sys-WebServer
- Sys-default
- sshroot@主機號登陸進去
- cd / (cd到根目錄)
- (安裝nginx)
yum install -y nginx
- cd /etc/nginx (可以通過ls檢視該資料夾下里的檔案和資料夾)
- ls (檢視一下nginx)
- vi nginx.conf(編輯nginx.conf)
- 把紅框的內容註釋掉,最下邊一行新增
include vhost/8.conf
- 在nginx下建立一個vhost資料夾(mkdir vhost)
- cd vhost
- vi ysr.bdplus.cn.conf(建立一個.conf檔案)
-
#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;(日誌資料夾地址) }
- 啟動nginx
systemctl start nginx.service
- 設定開機啟動
systemctl enable nginx.service
- 關閉nginx
systemctl stop nginx.service
- 重啟nginx
systemctl restart nginx.service