1. 程式人生 > 實用技巧 >liunx系統下安裝部署nginx 及配置前端專案的部署釋出

liunx系統下安裝部署nginx 及配置前端專案的部署釋出

準備目錄

[root@instance-3lm099to ~]# mkdir /usr/local/nginx
[root@instance-3lm099to ~]# cd /usr/local/nginx/

新增新增準備內容

[root@instance-3lm099to nginx-1.14.0]# yum -y install gcc gcc-c++ autoconf automake make
[root@instance-3lm099to nginx-1.14.0]# yum -y install openssl openssl-devel

下載

從http://nginx.org/download/上下載相應的版本(或者wget http://nginx.org/download/nginx-1.5.9.tar.gz直接在Linux上用命令下載)

解壓

解壓tar -zxvf nginx-1.5.9.tar.gz

解壓好後移至目錄

[root@instance-3lm099to nginx]# cd nginx-1.5.9/

設定Nginx安裝路徑,如果沒有指定,預設為/usr/local/nginx

[root@instance-3lm099to nginx-1.14.0]# ./configure --prefix=/usr/local/nginx

編譯

make(make的過程是把各種語言寫的原始碼檔案,變成可執行檔案和各種庫檔案)

[root@instance-3lm099to nginx-1.14.0]# make

安裝

make install (make install是把這些編譯出來的可執行檔案和庫檔案複製到合適的地方)

[root@instance-3lm099to nginx-1.14.0]# make install

啟動

引數 -c 指定了配置檔案的路徑,如果不加的話就是使用預設的配置檔案

[root@instance-3lm099to nginx-1.14.0]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

-------------------------------------以下是關於專案在nginx中的配置-------------------------------------

配置檔案內容(只展示中server中重要部分,其他相關配置查詢官網)   nginx.conf

    server {
    #監聽的埠 也就是瀏覽器要訪問的埠 listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main;
     # / 後面可以加專案名 也就是瀏覽器訪問的埠後面直接跟的專案名 location / {
       #前端程式碼的位置 可以直接將html檔案放入到 nginx下面的html中 也可以指定路徑 如 \data\qianduan root html; index index.html index.htm;
       #/index.html 專案的首頁地址,前面需要加上自己的檔名 \data\qianduan\ 下的專案名+首頁檔案所在的路徑
       try_files $uri $uri/ /index.html
}
    }