Nginx安裝

  1. 安裝nginx需要的linux環(huán)境:

    yum install   gcc-c++   -y  pcre pcre-devel  zlib zlib-devel  openssl openssl-devel
  1. 下載nginx

    cd /opt

    wget [http://nginx.org/download/nginx-1.10.3.tar.gz](http://nginx.org/download/nginx-1.10.3.tar.gz)

    tar xvf nginx-1.10.3.tar.gz
  1. 編譯安裝

    cd nginx-1.10.3

    #   /home/service/nginx 作為nginx安裝目錄

    ./configure --prefix=/home/service/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_ssl_module --with-http_stub_status_module --with-pcre --with-stream

    make && make install
  1. 使用nginx代理 ,修改配置文件

    vi   /home/service/nginx/conf/nginx.conf

    在http的{}外部添加以下內(nèi)容,例如:

    stream {
    server {

    listen 9001;

    proxy_connect_timeout 1s;
    proxy_timeout 3s;
    proxy_pass 172.51.20.180:9001;
    }
  1. 啟動(dòng)nginx
    先檢查配置文件是否有錯(cuò)誤: /home/service/nginx/sbin/nginx -t
    啟動(dòng)nginx: /home/service/nginx/sbin/nginx -c /home/service/nginx/conf/nginx.conf
  1. 重載配置文件

    /home/service/nginx/sbin/nginx -s reload
  1. 設(shè)置為開啟自啟動(dòng)

    vim /usr/lib/systemd/system/nginx.service # 內(nèi)容如下

    [Unit]
    Description=nginx
    After=network.target

    [Service]
    Type=forking
    ExecStart=/home/service/nginx/sbin/nginx
    ExecReload=/home/service/nginx/sbin/nginx -s reload
    ExecStop=/home/service/nginx/sbin/nginx -s quit
    PrivateTmp=true

    [Install]
    WantedBy=multi-user.target

設(shè)置開機(jī)自啟動(dòng)

systemctl enable nginx.service

查看nginx狀態(tài)

systemctl status nginx.service

顯示Active: inactive (dead),說明nginx已經(jīng)被啟動(dòng)了,殺死進(jìn)程: pkill -9 nginx

重啟: systemctl start nginx

[Unit]:服務(wù)的說明
Description:描述服務(wù)
After:描述服務(wù)類別
[Service]服務(wù)運(yùn)行參數(shù)的設(shè)置
Type=forking是后臺(tái)運(yùn)行的形式
ExecStart為服務(wù)的具體運(yùn)行命令
ExecReload為重啟命令
ExecStop為停止命令
PrivateTmp=True表示給服務(wù)分配獨(dú)立的臨時(shí)空間
注意:[Service]的啟動(dòng)、重啟、停止命令全部要求使用絕對(duì)路徑
[Install]運(yùn)行級(jí)別下服務(wù)安裝的相關(guān)設(shè)置,可設(shè)置為多用戶,即系統(tǒng)運(yùn)行級(jí)別為3

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

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

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