Nginx] [installation & configuration environment

Installation dependencies

安装make:yum -y install gcc automake autoconf libtool make
安装g++:yum -y install gcc gcc-c++
安装pcre和pcre-devel:yum install -y pcre pcre-devel
Install zlib zlib compression and decompression provides a lot of ways, nginx requires zlib to be http gzip: yum install -y zlib zlib- devel
(This can be given if yum install -y zlib zlib-devel --setopt = protected_multilib = false)
Installation OpenSSL OpenSSL is a Secure Sockets Layer cryptographic library, nginx to support https, need to use openssl: yum install -y openssl openssl- devel
 

Install Nginx

Decompression nginx: tar-xzvf  nginx-1.17.6.tar.gz
Enter nginx directory: cd nginx-1.17.6 /
Install Nginx:
./configure --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module 
make && make install
View nginx installation directory: whereis nginx (usually in / usr / local / nginx)
 

Environment variable configuration

Open system environment variable settings: vim / etc / profile 
Enter the red font section:
NGINX_HOME=/usr/local/nginx
export PATH=${NGINX_HOME}/sbin:${PATH} 
Settings to take effect: Source / etc / Profile
 
nginx -V 
Check module already exists, returns the following:

nginx version: nginx/1.17.6
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module

 

Configuration nginx.conf

nginx configuration directory: / usr / local / nginx / conf /

Start nginx: nginx -c /usr/local/nginx/conf/nginx.conf

View and edit nginx.conf:

vim nginx.conf

listen: listen port to 8089 (or other port 80 needed for the record)

server_name: Name (default native ip, such as domain names can be changed to customize: www.test.com)

root: the site root (html - "/ usr / local / nginx / html)

Save the changes: ": wq"

 Restart nginx entry into force: nginx -s reload

Check whether to restart successfully: ps aux | grep nginx

Restart unsuccessful: "kill -9 process id" or "nginx -s stop"

Need to kill two processes, otherwise the port is occupied not start successfully

 

Browser access: 

 

 

 

 

Configuring multiple sites on Nginx

1, in the nginx.conf directory create a folder: mkdir conf.d

2, nginx.conf copy of the current directory to the new folder: cp nginx.conf conf.d / site1.conf

3, edit site1.conf:

 server {
        listen       8081;
        server_name  www.site1.com;

        location / {
            root   html;
            index  index.html index.htm;
        }

         location /error/ {
            alias / sylvia / errorpages /;
        }
       
         location /ErrorPages/ {
            alias / sylvia / errorpages /;
            internal;
         }

        error_page 400 /ErrorPages/HTTP400.html;
        error_page 401 /ErrorPages/HTTP401.html;
        error_page 402 /ErrorPages/HTTP402.html;
        error_page 403 /ErrorPages/HTTP403.html;
        error_page 404 /ErrorPages/HTTP404.html;
        error_page 500 /ErrorPages/HTTP500.html;
        error_page 501 /ErrorPages/HTTP501.html;
        error_page 502 /ErrorPages/HTTP502.html;
        error_page 503 /ErrorPages/HTTP503.html;

    }

引入alias,创建虚拟目录。(参考:https://www.cnblogs.com/kevingrace/p/6187482.html

4、编辑根配置nginx.conf

在http{}里面最后一行添加:include conf.d/*.conf;

 

5、重启nginx

浏览器访问:域名+端口+path

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/fatCat1/p/11950221.html