Linux(Centos7)中Nginx的安裝

Linux(Centos7)中Nginx的安裝

安裝所需插件

1、安裝gcc

gcc是linux下的編譯器在此不多做解釋,感興趣的小夥伴可以去查一下相關資料,它可以編譯 C,C++,Ada,Object C和Java等語言

命令:查看gcc版本

gcc -v

一般阿里雲的centOS7裏面是都有的,沒有安裝的話會提示命令找不到,

安裝命令:

yum -y install gcc

2、pcre、pcre-devel安裝

pcre是一個perl庫,包括perl兼容的正則表達式庫,nginx的http模塊使用pcre來解析正則表達式,所以需要安裝pcre庫。

安裝命令:

yum install -y pcre pcre-devel

3、zlib安裝

zlib庫提供了很多種壓縮和解壓縮方式nginx使用zlib對http包的內容進行gzip,所以需要安裝

安裝命令:

yum install -y zlib zlib-devel

4、安裝openssl

openssl是web安全通信的基石,沒有openssl,可以說我們的信息都是在裸奔。。。。。。

安裝命令:

yum install -y openssl openssl-devel

安裝nginx

1、下載nginx安裝包

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

如果命令無法進行

yum -y install wget

這裏需要到/usr/local/ 新建java的文件夾

2、把壓縮包解壓到usr/local/java

tar -zxvf  nginx-1.9.9.tar.gz

3、切換到cd /usr/local/java/nginx-1.9.9/下面

執行三個命令:

./configure
 
make
 
make install

4、切換到/usr/local/nginx安裝目錄

5、配置nginx的配置文件nginx.conf文件,主要也就是端口

可以按照自己服務器的端口使用情況來進行配置

ESC鍵,wq!強制保存並退出

6、啓動nginx服務

切換目錄到/usr/local/nginx/sbin下面

啓動nginx命令:

./nginx
./nginx -s reload

7、查看nginx服務是否啓動成功

ps -ef | grep nginx

8、訪問你的服務器IP

如果訪問不了,關閉防火牆

查看防火牆狀態:systemctl status firewalld
關閉防火牆:systemctl stop firewalld
開啓防火牆:systemctl start firewalld

nginx.conf說明

#user  nobody;
worker_processes  1; #工作進程:數目。根據硬件調整,通常等於cpu數量或者2倍cpu數量。
 
#錯誤日誌存放路徑
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
 
#pid        logs/nginx.pid; # nginx進程pid存放路徑
 
 
events {
    worker_connections  1024; # 工作進程的最大連接數量
}
 
 
http {
    include       mime.types; #指定mime類型,由mime.type來定義
    default_type  application/octet-stream;
 
    # 日誌格式設置
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';
 
    #access_log  logs/access.log  main; #用log_format指令設置日誌格式後,需要用access_log來指定日誌文件存放路徑
					
    sendfile        on; #指定nginx是否調用sendfile函數來輸出文件,對於普通應用,必須設置on。
			如果用來進行下載等應用磁盤io重負載應用,可設着off,以平衡磁盤與網絡io處理速度,降低系統uptime。
    #tcp_nopush     on; #此選項允許或禁止使用socket的TCP_CORK的選項,此選項僅在sendfile的時候使用
 
    #keepalive_timeout  0;  #keepalive超時時間
    keepalive_timeout  65;
 
    #gzip  on; #開啓gzip壓縮服務
 
    #虛擬主機
    server {
        listen       80;  #配置監聽端口號
        server_name  localhost; #配置訪問域名,域名可以有多個,用空格隔開
 
        #charset koi8-r; #字符集設置
 
        #access_log  logs/host.access.log  main;
 
        location / {
            root   html;
            index  index.html index.htm;
        }
        #錯誤跳轉頁
        #error_page  404              /404.html; 
 
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
 
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}
 
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ { #請求的url過濾,正則匹配,~爲區分大小寫,~*爲不區分大小寫。
        #    root           html; #根目錄
        #    fastcgi_pass   127.0.0.1:9000; #請求轉向定義的服務器列表
        #    fastcgi_index  index.php; # 如果請求的Fastcgi_index URI是以 / 結束的, 該指令設置的文件會被附加到URI的後面並保存在變量$fastcig_script_name中
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}
 
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }
 
 
    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;
 
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
 
 
    # HTTPS server
    #
    #server {
    #    listen       443 ssl;  #監聽端口
    #    server_name  localhost; #域名
 
    #    ssl_certificate      cert.pem; #證書位置
    #    ssl_certificate_key  cert.key; #私鑰位置
 
    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m; 
 
    #    ssl_ciphers  HIGH:!aNULL:!MD5; #密碼加密方式
    #    ssl_prefer_server_ciphers  on; # ssl_prefer_server_ciphers  on; #
 
 
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章