nginx部署多個前端項目

這里就不介紹同一端口和同一nginx.conf,有需要的童鞋自行百度。
這里介紹不同項目的不同配置。
服務(wù)器中已經(jīng)部署了其他項目,這里做一個簡單的頁面做測試:

1、新建目錄:
/root/nginx/8571/
/root/nginx/8571/html/
/root/nginx/8571/log/

2、將文件:/usr/sbin/nginx 拷貝至 /root/nginx/8571/
3、新建index.html:/root/nginx/8571/html/index.html

<!DOCTYPE html>
<html lang="zh-cmn-Hans">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>12</title>
  </head>
  <body>
    <div id="app">
      cesi
    </div>
         </body>
</html>

4、新建配置文件:/root/nginx/8571/nginx.conf


微信圖片_20220623180125.png
user root;
worker_processes auto;
pid /root/nginx/8571/nginx.pid;
include   /etc/nginx/modules-enabled/*.conf;
events {
    worker_connections 768;
}
http {
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;

    include /usr/local/nginx/conf/mime.types;
    default_type application/octet-stream;

    # ssl_protocols TLSV1 TLSv1.1 TLSv1.2; # Dropping SsLv3,ref: POODLE 
    # ssl_preter serverciphers on;
    #access_log /root/nginx/8571/log/access.log;
    #error_log root/nginx/8571/error.log;
    gzip on;
    gzip_disable "msie6";
server {
    listen 8571; 
    location /{
        root /root/nginx/8571/html/;
        index index.html index.htm;

        }
    }
}

5、啟動 nginx
./nginx -c /root/nginx/8571/nginx.conf

注意:
若 nginx.conf 配置 location 后,重啟 nginx 再訪問,如果訪問提示:Nginx 403 Forbidden,則需要在 nginx.conf 頭部加入一行:

user root;

查看nginx端口使用情況:netstat -apn
啟動成功后輸入ip和端口8571訪問:


微信圖片_20220623180438.png

關(guān)注小編不定時更新更多精彩內(nèi)容

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容