linux服務器下部署nginx

linux (centos)安裝部署nginx

1. 背景

今年加入的新公司以前沒有先後端分離的項目,我也在入職後在參與的第一個項目中推進了公司的第一個先後端分離項目。由於先後端分離,前端代碼的部署須要用到ngnix。因爲以前並無使用nginx的經驗,因此此次部署過程當中,根據網絡上搜到的資料,將不走一步一步記錄下來,最終完成部署。如今,將他寫成筆記,供後續查閱,也但願給有和我同樣需求的ngnix小白帶來一點幫助。html

2. 起步

首先,咱們從網絡下載nginx壓縮包前端

  1. ngnix-1.12.2.tar.gz複製到opt/soft
  2. tar -zxvf ngnix-1.12.2.tar.gz
安裝nginx
一、安裝prce(重定向支持)和openssl(https支持,若是不須要https能夠不安裝。)
            
    - yum -y install pcre*
    - yum -y install openssl*
    - tar  -zxvf ngnix-1.12.2.tar.gz
    - ./configure --prefix=/usr/local/nginx(必須先建好目錄)
            
    - make 
    - make install (這步報錯了,可是沒有影響後面)
    ```
        (error: make *** No rule to make target 'build', need by 'default' stop) 
        # unbuntu
        apt-get install openssl
        apt-get install libssl-dev

        # centos
        yum -y install openssl openssl-devel
    ```
  1. 打包文件放到: home文件夾下 /home/dist // 前端包位置
  2. 修改nginx配置文件conf/nginx.confvue

    server {
            listen 8080;
            server_name localhost;
            
            location / {
                root home/dist; # 前端包位置
                index index.html index.htm;
                try_files $uri/ /index.html;  # 使vue單頁應用支持新開窗口
            }
            location /urlname {
                poxy_pass http://10.10.10.12:8080 // 代理後臺服務地址
            }
            # ...
        }
  3. 啓動nginxpython

    nginx -c /opt/soft/nginx-1.11.13/conf/nginx.conf
        ps -ef|grep nginx
    
        kill -INT 777 
        or
        kill -QUIT 1011

6 提示:nginx nginx command not foundlinux

https://blog.csdn.net/pythondafahao/article/details/79826290
    // 修改profile文件
    ```
        vim /etc/profile
        
        export PATH=$PATH:/usr/local/nginx/sbin
        
        source /etc/profile 刷新
    
    ```

7 再次啓動項目nginx

nginx -c /opt/soft/nginx-1.11.13/conf/nginx.conf
    ps -ef|grep nginx

3. 總結

如今咱們已經完成了nginx的安裝,並完成了前端代碼的配置。nginx還有不少功能須要學習,我也會在將來學習實踐後記錄下來,繼續堅持分享vim

相關文章
相關標籤/搜索