Installation and configuration nginx linux

First, the software installation

1, Environment Description

OS: CentOS 7.4 64 bit

nginx Version: 1.16.1

Installation Date: 2019/10/01

Installing user: root

2, install the runtime

yum -y install gcc gcc-c++ automake autoconf libtool make

3, install openssl (no installation, you can extract)

$ cd /usr/local/src
$ wget https://www.openssl.org/source/openssl-1.0.1t.tar.gz
$ tar -zxvf openssl-1.0.1t.tar.gz

4, install pcre

$ cd /usr/local/src
$ wget https://ftp.pcre.org/pub/pcre/pcre-8.38.tar.gz
$ tar -zxvf pcre-8.38.tar.gz
$ cd pcre-8.38
$ ./configure
$ make
$ make install

5, install zlib

$ cd /usr/local/src
$ wget http://zlib.net/zlib-1.2.11.tar.gz
$ tar -zxvf zlib-1.2.11.tar.gz
$ cd zlib-1.2.11
$ ./configure
$ make
$ make install

6, install nginx

$ cd /usr/local/src
$ wget http://nginx.org/download/nginx-1.16.1.tar.gz
$ tar -zxvf nginx-1.16.1.tar.gz
$ cd nginx-1.16.1
 
$ ./configure --with-http_ssl_module \
--with-pcre=/usr/local/src/pcre-8.38 \
--with-zlib=/usr/local/src/zlib-1.2.11 \
--with-openssl=/usr/local/src/openssl-1.0.1t
 
$ make
$ make install

Second, the software using the command

nginx default installation path is / usr / local / nginx

Start: ./ sbin / nginx

关闭:/usr/local/nginx/sbin/nginx -s stop

重启:/usr/local/nginx/sbin/nginx -s reopen

Reload the configuration file: / usr / local / nginx / sbin / nginx -s reload

Third, the software configuration

 

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    proxy_cache_path D:/nginx-1.16.1/cache levels=1:1:1 keys_zone=pcache:10m max_size=2g;

    #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;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       55556;
        server_name  127.0.0.1;

    proxy_cache pcache; # call cache
    proxy_cache_key $ request_uri; # key to what happens when
    proxy_cache_methods GET HEAD; # cache which items
    proxy_cache_valid 200 is  302 10m; # 200302 response code specified content cache 10 minutes
    proxy_cache_valid 404       1M; # 404 response code specified content caching 1 minute
    proxy_cache_use_stale http_502; # 502 allows the content of the response code using an outdated cached
    the X-proxy_set_header -Real- IP $ REMOTE_ADDR; # the actual client IP sent to the back-end server
    the X-add_header - Via $ server_addr; # proxy server IP sent to the back-end server

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
        proxy_pass  http://127.0.0.1:55555/;
            root   html;
            index  index.html index.htm;
        }
        
    location /nationInterface/ {
        proxy_pass  http://124.163.214.106:18064/nationInterface/;
            root   html;
            index  index.html index.htm;
        the X-proxy_set_header -Real- IP $ REMOTE_ADDR; # the actual client IP sent to the back-end server
        the X-add_header - Via $ server_addr; # proxy server IP sent to the back-end server
        }
        
    
    location /CMAQ {
        auto index is;
            root   D:/dataCenter;
        add_header Cache-Control no-cache;
        add_header Pragma no-cache;
        add_header Expires 0;
        }

        #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$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    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;

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

}

 

Note: When configuring a static directory, using the directory splicing methods, such as on a static map directory is: D: / dataCenter / CMAQ /.

If you experience permission issues under linux, such as 13: Permission denied. Troubleshoot from the following aspects:

1, root installation, you have to start with the root user

2, nginx.conf the first line of the configuration file, # user nobody wanted to change user root

3, is missing index.html

4, modify directory permissions: chmod -R 777 / data

5, to SELinux set to off.

 

Guess you like

Origin www.cnblogs.com/tiandi/p/12119096.html