Installation and configuration of Nginx

Source: Internet
Author: User

1. Installation Instructions:

System Environment: Ubuntu 14.04.3 LTS

Software: nginx-1.8.0.tar.gz

Installation Location: /opt/nginx

2. Installation

The installation package that needs to be used:

Openssl-fips-2.0.10.tar.gz

Zlib-1.2.8.tar.gz

Pcre-8.37.tar.gz

Nginx-1.8.0.tar.gz

the installation order is : OpenSSL , zlib , Pcre, then install Nginx Package

2.1 installation openssl-fips-2.0.2.tar.gz

TAR–ZXVF openssl-fips-2.0.10.tar.gz

CD openssl-fips- 2.0 . Ten

./config

Make

Make install

2.2 Installation zlib-1.2.8.tar.gz

TAR–ZXVF zlib-1.2.8.tar.gz

CD zlib-1.2.8

./configure

Make

Make install


2.3 install pcre-8.37.tar.gz ( need to install compiled C + + environment: Apt-get install build-essential )

in the installation pcre-8.37.tar.gz before you need to install C + + compile the environment, or execute the ./configure will be an error.

Apt-get Install Build-essential

TAR–ZXVF pcre-8.37.tar.gz

CD pcre-8.37

./configure

Make

Make install


2.4 Installation nginx-1.8.0.tar.gz

TAR-ZXVF nginx-1.8.0.tar.gz

CD nginx-1.8.0

./configure--with-pcre=. /pcre-8.37--with-zlib=. /zlib-1.2.8--with-openssl=. /openssl-fips-2.0.10

Make

Make install

so far Nginx installation is complete !

detects if Nginx is installed successfully

Cd/usr/local/nginx/sbin

./nginx–t

the prompt appears as shown below , indicates successful installation

Root@wcyong:/usr/local/nginx/sbin#./nginx-t

Nginx:the configuration file/usr/local/nginx/conf/nginx.conf syntax is OK

Nginx:configuration file/usr/local/nginx/conf/nginx.conf Test is successful


Start Nginx

./ngixn

To view ports:

NETSTAT-TNLP | grep nginx

Root@wcyong:/usr/local/nginx/sbin# NETSTAT-TNLP | grep nginx

TCP 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 2957/nginx


and access through the browser


3.nginx Load Balancer configuration

Open the/usr/local/nginx/conf/nginx.conf configuration file and configure it as follows:

user  root root;worker_processes  1;  #error_log   logs/error.log; #error _log  logs/error.log  notice;error_log  logs/error.log  warn; pid         logs/nginx.pid;  events {     worker_connections  1024;}   http {    include       mime.types;     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;     sendfile         on;     #tcp_nopush      on;       #keepalive_timeout   0;    keepalive_timeout  65;       #gzip   on;      #设定负载均衡的服务器列表      upstream myserver{     server 192.168.1.171:8080;                  server  192.168.1.172:8080;                  server 192.168.1.173:8080;    }      #侦听服务器信息     server {        listen       80;         server_name  192.168.1.110;                 #charset  koi8-r;           #access_log   logs/host.access.log  main;          location / {                           #root     html;                           #index   index.html index.htm;                           proxy_pass http://myserver;                          proxy_redirect off;                           proxy_set_header Host  $host;                           proxy_set_header X-Real-IP  $remote _addr;                          # Backend Web server can get the user real ip             through x-forwarded-for              proxy_set_header  x-forwarded-for  $proxy _add_x_forwarded_for;        }         # 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;    #    &nbSP;}     #} }


Installation and configuration of Nginx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.