安裝Nginx到CentOS(YUM)


運行環境

系統版本:CentOS Linux release 7.3.1611
軟件版本:nginx-1.12.2
硬件要求:無

安裝過程

1、配置YUM源

[root@localhost ~]# rpm -i https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
[root@localhost ~]# yum clean all
[root@localhost ~]# yum makecache

2、安裝NGINX

RPM版的NGINX軟件包分為主軟件包和擴展模板包,主軟件包只提供基本的WEB+反向代理功能,則其他擴展模塊包則實現一些其他的高級功能,默認情況下安裝主軟件包,則擴展模塊包也會安裝。

[root@localhost ~]# yum search nginx
nginx-all-modules.noarch : A meta package that installs all available Nginx modules
nginx-filesystem.noarch : The basic directory layout for the Nginx server
nginx-mod-http-geoip.x86_64 : Nginx HTTP geoip module
nginx-mod-http-image-filter.x86_64 : Nginx HTTP image filter module
nginx-mod-http-perl.x86_64 : Nginx HTTP perl module
nginx-mod-http-xslt-filter.x86_64 : Nginx XSLT module
nginx-mod-mail.x86_64 : Nginx mail modules
nginx-mod-stream.x86_64 : Nginx stream modules
nginx.x86_64 : A high performance web server and reverse proxy server(主程序包)
[root@localhost ~]# yum -y install nginx

3、編輯主配置文件,添加一個新Web站點的配置

[root@localhost ~]# vim /etc/nginx/nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
    worker_connections 1024;
}
http {
    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  /var/log/nginx/access.log  main;
    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;
    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;
    include /etc/nginx/conf.d/*.conf;
	

    #==WEB站點配置==#
    server {
        listen       80 default_server;
        #監聽IPV4的地址與端口,地址為空表示監聽所有,“default_server”即默認服務器,DNS映射一個域名
        #到該主機,但是當用戶訪問的這個域名與這些WEB虛擬主機綁定的域名都不匹配的情況下,默認由監
        #聽“default_server”的虛擬主機呈現內容。
        listen       [::]:80 default_server;
        #監聽IPV6的地址與端口。
        server_name  _;
        #域名綁定,綁定一個域名。
        location / {
        #匹配“/”,即用戶訪問“server_name/”時則呈現里面定義的內容。
          root	/usr/share/nginx/html;
          #WEB應用根目錄。
    	  index index.html;
          #默認呈現的首頁文件,當用戶訪問域名或IP地址是自動索引呈現該文件中的內容。
        }
        error_page 404 /404.html;
       #HTTP請求錯誤響應碼,反饋給用戶的頁面文件位置。
        location = /40x.html {
        #匹配上面的錯誤頁面。
        }
        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }
}

4、創建一個靜態頁面存放到站點配置所指定的發布目錄下

[root@localhost ~]# vim /usr/share/nginx/html/index.html
hello world!

5、開啟服務

[root@localhost ~]# systemctl start nginx
[root@localhost ~]# netstat -lnupt |grep :80
tcp    0      0 0.0.0.0:80    0.0.0.0:*       LISTEN      14379/nginx: master 

6、使用瀏覽器訪問WEB

在瀏覽器輸入:http://Server_IP

7、查看NGINX版本和安裝了那些模塊

[root@localhost ~]# nginx -V
nginx version: nginx/1.12.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_auth_request_module --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-google_perftools_module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --with-ld-opt='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E'


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM