linux-nginx

首先我們跳轉到nginx安裝的地方

cd usr/local

下載nginx: 測試使用1.16.1

wget http://nginx.org/download/nginx-1.16.1.tar.gz 

其他版參照官網地址:http://nginx.org/en/download.html
在這裏插入圖片描述

  1. 解壓到當前目錄下:
tar -zxvf  nginx-1.16.1.tar.gz
  1. 執行命令:

在這裏插入圖片描述

在這裏插入圖片描述

在這裏插入圖片描述

如果以上三個步驟出現了問題,基本是一些插件編輯器沒有安裝,安裝如下:

安裝插件:在根目錄安裝即可

  1. 查看gcc是否安裝

    gcc是語言編輯器,當下可以編輯基本所有的高級語言如java/pascal/go等以及C、C++

gcc -v

安裝方法:

yum -y install gcc

在這裏插入圖片描述

  1. 安裝pcre
    解決正則以及函數的使用
yum install -y pcre pcre-devel

在這裏插入圖片描述

  1. 安裝zlib:
    提供各種的壓縮方式
yum install -y zlib zlib-devel
  1. 安裝openssl
    開源的安全通信包
yum install -y openssl openssl-devel

!最後回到下載nginx裏面的步驟三個命令即可完成nginx的安裝成功

修改nginx端口號等配置

  1. 此時在usr/local裏面會產生一個nginx文件夾
cd usr/local/nginx/conf

在這裏插入圖片描述

  1. 打開nginx.conf文件編輯下
vi nginx.conf

在這裏插入圖片描述

  1. 配置如下
user admin;  #用戶名
worker_processes  1;  #工作進程:數目。根據硬件調整,通常等於cpu數量或者2倍cpu數量。
pid         /usr/local/nginx/logs/nginx.pid;  # nginx進程pid存放路徑

events {
    worker_connections  1024; # 工作進程的最大連接數量
}
##test

http {
    include       mime.types; #指定mime類型,由mime.type來定義
    default_type  application/octet-stream;
    sendfile        on; #指定nginx是否調用sendfile函數來輸出文件,對於普通應用,必須設置on。
    keepalive_timeout  65;
    
	## 虛擬主機
    server {
        listen       80;  #開啓端口
        server_name physical.tdr.tech;  #端口號域名代替ip地址(192.168.0.2) 域名可以有多個,用空格隔開

       #壓縮轉發:基本默認爲以下內容
        gzip  on;
        gzip_vary on;
        gzip_min_length 100k;
        gzip_buffers 128 128k;
        gzip_comp_level 6;
        gzip_types  text/plain application/javascript application/x-javascript application/json text/css text/scss application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png image/x-icon;
        client_max_body_size 200M;
        proxy_connect_timeout 10;
        proxy_send_timeout 30;
        proxy_read_timeout 60;
        #壓縮轉發
        
        #默認ip地址啓動的地址,比如ip地址:192.168.0.2,啓動後會看到index.html內容
        location / {
            root   html;
            index  index.html index.htm;
        }

        # 項目啓動地址:192.168.0.2/ftdp_mobile_prod
        location /ftdp_mobile_prod {
            root /home/admin/physical-ftdp;
            index index.html;
        }
		#local/html/50.html文件
        location = /50x.html {
            root   html;
        }
    }
}

啓動nginx:

  1. 進入usr/local/nginx/sbin
cd usr/local/nginx.sbin

在這裏插入圖片描述

  1. 啓動nginx
./nginx
  1. 重啓nginx
./nginx -s reload


# 判斷是配置文件是否正常:
./nginx -t
  1. 關閉nginx
#查詢nginx主進程號
ps -ef|grep nginx

#正常停止: 
kill -QUIT 主進程號

#快速停止
kill -TERM 主進程號

#強制停止
kill -9 nginx

#如果nginx.com配置了pid文件路徑,如果沒有則在logs目錄下
kill -信號類型'usr/local/nginx/logs/nginx.pid'

訪問ip地址:192.168.0.2 即可訪問到
可以將這個服務器所有地址放到usr/local/html/index.html中,在裏面配置超鏈接即可

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章