1.安裝編譯工具及庫文件
# yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel pcre-devel
gcc、gcc-c++ # 主要用來進行編譯相關使用
openssl、openssl-devel # 一般當配置https服務的時候就需要這個了
zlib、zlib-devel # 主要用於文件的解壓縮
pcre、pcre-devel # Nginx的rewrite模塊和HTTP核心模塊會用到PCRE正則表達式語法
make # 遍歷
make install # 安裝
2.創建nginx目錄
1)進入/usr/local目錄下
# cd /usr/local
2)創建nginx文件
# mkdir nginx
3.下載並解壓nginx
1)進入nginx文件下
# cd /usr/local/nginx
2)下載nginx安裝包
# wget https://nginx.org/download/nginx-1.18.0.tar.gz
3)解壓
# tar -zxvf nginx-1.18.0.tar.gz
4.進入安裝包目錄
# cd /usr/local/nginx/nginx-1.18.0
5.編譯安裝nginx,默認安裝到 /usr/local/nginx中
./configure
make && make install
6.進入到/usr/local/nginx/sbin目錄,啟動nginx
# ./nginx
7.查看啟動的 nginx 進程
ps -ef|grep nginx
8、查看是否可以訪問
# curl localhost:80
出現html腳本代表可以訪問
9.對項目進行打包
1)在vscode中打開項目路徑下的終端,輸入npm run build
2)打包完成后,會在項目路徑生產一個dist的文件,將dist文件重命名為dist-atp(命名可自定義)
3)將dist-atp文件上傳到服務器的/usr/local/nginx/html路徑下
10.配置nginx.conf
cd /usr/local/nginx/conf
vim nginx.conf
1 #啟動的進程數量 2 worker_processes 1; 3 events { 4 #單個進程並發量 5 worker_connections 1024;#總並發量=單個進程並發量*啟動的進程數量 6 } 7 http { 8 include mime.types; 9 default_type application/octet-stream; 10 sendfile on; 11 keepalive_timeout 65;#連接服務器超時時長65s 12 #虛擬主機配置 13 14 server {#一個虛擬主機配置,多個虛擬機就配置多個 15 listen 8888; 16 server_name 123.57.1.35; #域名解析 17 location / {#配置默認訪問頁 18 root /usr/local/nginx/html/dist; 19 index index.html index.htm;#訪問的首頁 20 try_files $uri $uri/ @router; 21 } 22 location ./ { 23 # 代理轉發到后台服務接口,注意后面英文分號;不要少了 24 proxy_pass http://123.57.1.35:8090/jeecg-boot/swagger-ui.html; 25 } 26 location @router{ 27 #rewrite ^.*/index.html last; 28 rewrite ^(.+)$ /index.html last; 29 } 30 error_page 500 502 503 504 /50x.html; 31 location = /50x.html { 32 root html; 33 } 34 } 35 }
保存文件
按esc
:wq
11.查看nginx.conf配置是否正確
/usr/local/nginx/sbin/nginx -t
12.在/usr/local/nginx/html目錄下上傳dist項目包,並對項目包進行解壓
13.在/usr/local/nginx/sbin目錄下重啟nginx
# ./nginx -s reload
13.在瀏覽器輸入域名:端口進行訪問
附件內容如下:
啟動,重啟,停止nginx
cd /usr/local/nginx/sbin/
./nginx #啟動
./nginx -s stop #停止
./nginx -s quit #退出
./nginx -s reload #重啟 修改配置后重新加載生效<br><br>./nginx -s reopen :重新打開日志文件<br>
./nginx -s quit:此方式停止步驟是待nginx進程處理任務完畢進行停止。
./nginx -s stop:此方式相當於先查出nginx進程id再使用kill命令強制殺掉進程。
啟動方法二
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
停止方法二
ps -ef|grep nginx #查詢進程號
kill -QUIT 主進程號 #從容停止
kill -TERM 主進程號 #快速停止
kill -9 主進程號 #強制停止
注:訪問外網ip(注意如果是阿里雲服務器需要先配置安全組規則)