Nginx Open source and cross-platform software developed by the Russian people to provide Web services and agency services
Nginx provides Web Services application environment?
1. Virtual Hosting
2. User Access control
3. User authentication
4. Anti-theft chain
Lab Environment:
Installation software: nginx-0.855.tar.gz
Operating system: centos6.5
Experiment: (i)
Experimental purpose: The installation of Nginx source package and basic use.
Install the source package tools to install: Development tools and development environment
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/A3/wKioL1XqfgehFjvrAAAlODOmxGA307.jpg "title=" Qq20150905132324.png "alt=" Wkiol1xqfgehfjvraaalodomxga307.jpg "/>
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/72/A3/wKioL1XqfsfiJjUWAAAmL7mDR60215.jpg "title=" Qq20150905132704.png "alt=" Wkiol1xqfsfijjuwaaaml7mdr60215.jpg "/>
1. Install Nginx Source Package
Set up Ngix software folder to store Nginx package
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/72/A7/wKiom1XqfwmihLjLAAAW-YfOKp8694.jpg "title=" Qq20150905133723.png "alt=" Wkiom1xqfwmihljlaaaw-yfokp8694.jpg "/>
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/A7/wKiom1Xqf_bC23AQAADEd0E66k8664.jpg "title=" Qq20150905134117.png "alt=" Wkiom1xqf_bc23aqaaded0e66k8664.jpg "/>
Add the owner of a process and the owning group for Www,www as the owner of the Nginx process and the owning group.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/A4/wKioL1Xqg-_SRTyOAAA4VKl7SiM258.jpg "title=" Qq20150905134847.png "alt=" Wkiol1xqg-_srtyoaaa4vkl7sim258.jpg "/>
To configure the source package,--prefix Specify the directory of Nginx configuration,--user Specify the owner,--group specify the owning group,--with-http_ssl_module specify the module that the user can access with HTTPS,--WITH-HTTP_ STUB_STATUS_MODULE specifies the module for viewing the information that Nginx is accessing through a Web page.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/72/A6/wKioL1XqpCaiqISUAADTtUlmxps869.jpg "title=" Qq20150905160555.png "alt=" Wkiol1xqpcaiqisuaadttulmxps869.jpg "/>
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/72/A6/wKioL1XqplHgkg8pAAGRDq9gYdY281.jpg "title=" Qq20150905160343.png "alt=" Wkiol1xqplhgkg8paagrdq9gydy281.jpg "/>
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/72/AA/wKiom1XqpDXCcVwvAADGUPOxsw0355.jpg "title=" Qq20150905160517.png "alt=" Wkiom1xqpdxccvwvaadgupoxsw0355.jpg "/>
The following error occurs when installing through the above HTTP rewrite (address rewriting module requires Pcre library, requires installation of Pcre Library), rewrite address rewriting modifies client access to its own URL path, using Perl-style regular expressions to match user access to their own URL source path (PCRE library).
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/AA/wKiom1XqpKKiu66eAAGLeANsHnY870.jpg "title=" Qq20150905161655.png "alt=" Wkiom1xqpkkiu66eaagleanshny870.jpg "/>
Check the system installed Pcre package for those, the package has those, if not all installed with Yum installation, Pcre-devel package for Pcre software to provide library files.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/72/A6/wKioL1XqqbKxnfG3AAGPyMnuuxA199.jpg "title=" Qq20150905162914.png "alt=" Wkiol1xqqbkxnfg3aagpymnuuxa199.jpg "/>
The source package is configured again with an error, and the following error occurs.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/72/AA/wKiom1XqqDvC7WvgAAFlNKD5SxI975.jpg "title=" Qq20150905163308.png "alt=" Wkiom1xqqdvc7wvgaaflnkd5sxi975.jpg "/>
Installing the OpenSSL library file
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/A6/wKioL1XqqvWAIpQ8AAN5v6onhg4029.jpg "title=" Qq20150905163533.png "alt=" Wkiol1xqqvwaipq8aan5v6onhg4029.jpg "/>
Installing Make&make Install
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/A6/wKioL1Xqq1njK097AABV8p3xP6M983.jpg "title=" Qq20150905163646.png "alt=" Wkiol1xqq1njk097aabv8p3xp6m983.jpg "/>
2.nginx directory content conf for the configuration file directory, HTML for the Web directory, logs for the log directory, sbin for the startup directory.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/72/AA/wKiom1Xqqe6CD2NeAACtC9b9W8Y744.jpg "title=" Qq20150905164006.png "alt=" Wkiom1xqqe6cd2neaactc9b9w8y744.jpg "/>
View the files under each directory, nginx.conf the main profile, Nginx.conf.default as the profile template, index.html as the default Web page, Nginx is the startup command.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/A6/wKioL1XqrZyDMa8rAAIUoVMCveQ525.jpg "title=" Qq20150905164632.png "alt=" Wkiol1xqrzydma8raaiuovmcveq525.jpg "/>
The default Nginx port is 80, to see if there are other processes that occupy 80 ports if there is a shutdown.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/72/AA/wKiom1XqrDaxuMaNAAFNab18Q4A122.jpg "title=" Qq20150905165006.png "alt=" Wkiom1xqrdaxumanaafnab18q4a122.jpg "/>
3. Start the Nginx service (Sbin/nginx, and view the contents of the port process and logs, Access.log for the access log, Error.log for the error log, and nginx.pid for the process PID number.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/72/AA/wKiom1XqrUqSS24zAAEqegcEnIc590.jpg "title=" Qq20150905165428.png "alt=" Wkiom1xqruqss24zaaeqegcenic590.jpg "/>
Stop Nginx Service
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/A6/wKioL1XqsWXCm3xxAACVGViyCJU674.jpg "title=" Qq20150905170304.png "alt=" Wkiol1xqswxcm3xxaacvgviycju674.jpg "/>
Start the Nginx configuration parameters,-T to check the configuration file for errors,-V to view the Nginx version information,-V to view the Nginx configuration parameters,-C To specify additional configuration files,-s Stop nginx Service,-H to view help information.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/72/AA/wKiom1XqsLKCSnWXAALCyEvd_nQ757.jpg "title=" Qq20150905170840.png "alt=" Wkiom1xqslkcsnwxaalcyevd_nq757.jpg "/>
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/72/A6/wKioL1XqsuGxT7eIAABGqmUcgME110.jpg "title=" Qq20150905170851.png "alt=" Wkiol1xqsugxt7eiaabgqmucgme110.jpg "/>
Other ways to stop a service
Pkill-9 Nginx
Kill-Signal Nginx
term, INT quick close
QUIT calmly close, close the main process and close the working child process by the way
HUP start a new work process with a new configuration gracefully close the old worker process
USR1 Reopen log file
USR2 Smooth Upgrade Executable program
WINCH gracefully shuts down the worker process and does not immediately close the child process
Kill-hup ' cat/usr/local/nginx/logs/nginx.pid ' restart service
Experiment (II)
Experimental Purpose: The company currently has a number of sites to be published, due to limited funds and in order to save resources and improve the utilization of resources, the company decided to publish multiple sites on a single server and user access to do some restrictions.
1. Domain-based virtual host
Lab Environment:
The IP address of the server: 192.168.1.10, Web hosting directory for/wwwdir and/bbsdir,
The default page for a Web page directory is/wwwdir/index.html content of wwwpage,/bbsdir/index.html content is bbspage. Host names are: Www.tarena.com and bbs.tarena.com.
IP address of client: 192.168.1.20
Modify the main configuration file (delete blank lines in the main configuration file and lines with #), the server represents a web directory, listen listening port, server_name is the host name, location represents the Web page storage information, root for the web directory, Index is the Web page of the Web directory.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/AB/wKiom1XqwumwePOAAACPrF1nVT4427.jpg "title=" Qq20150905182653.png "alt=" Wkiom1xqwumwepoaaacprf1nvt4427.jpg "/>
See if there is an error in the master configuration file.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/AB/wKiom1XqyeyT6hSyAADCQgaQxqI281.jpg "title=" Qq20150905185636.png "alt=" Wkiom1xqyeyt6hsyaadcqgaqxqi281.jpg "/>
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/AB/wKiom1XqxYDwxxbHAAD0NDOJHgw288.jpg "title=" Qq20150905183802.png "alt=" Wkiom1xqxydwxxbhaad0ndojhgw288.jpg "/>
Restarting the Nginx service
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/72/A7/wKioL1XqyqrAi8LzAAA73Vh35Kg173.jpg "title=" Qq20150905185052.png "alt=" Wkiol1xqyqrai8lzaaa73vh35kg173.jpg "/>
The contents of the directory/wwwdir/index.html are created as wwwpage,/bbdir/index.html content is bbspage.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/72/AB/wKiom1XqxkyQgIzMAAEpp8SOGJw542.jpg "title=" Qq20150905184125.png "alt=" Wkiom1xqxkyqgizmaaepp8sogjw542.jpg "/>
Test whether a Web page can be accessed by the client
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/A7/wKioL1XqyX6xyW3CAACnjBt5l-U110.jpg "title=" Qq20150905184539.png "alt=" Wkiol1xqyx6xyw3caacnjbt5l-u110.jpg "/>
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/A7/wKioL1XqzPqSYwj8AACGFv2VDz8101.jpg "title=" Qq20150905190044.png "alt=" Wkiol1xqzpqsywj8aacgfv2vdz8101.jpg "/>
2. Port-based virtual host (user access is differentiated by the port accessed by the client).
Lab Environment:
IP address of the server: 192.168.1.10, Web hosting directory is the default HTML and/bbsdir,
The default page for a Web page directory is index.html content of wwwpage,/bbsdir/index.html content is bbspage. Host Name: www.tarena.com
When the user accesses the http://www.tarena.com:80 displayed as the default Nginx Web page content is wwwpage
When the user accesses the http://bbs.tarena.com:8080 displayed as a bbspage in the/bbsdir directory
(1). Create a Web page directory
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/72/A8/wKioL1Xq8D-DwmeSAABtj8TIHuY625.jpg "title=" Qq20150905213111.png "alt=" Wkiol1xq8d-dwmesaabtj8tihuy625.jpg "/>
(2). Modifying the master configuration file
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/72/AC/wKiom1Xq7wvw4Qt3AADBbMt2MiI306.jpg "title=" Qq20150905213515.png "alt=" Wkiom1xq7wvw4qt3aadbbmt2mii306.jpg "/>
(3). Restart the service
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/72/AC/wKiom1Xq7-3w6pEDAAA970NkLJU055.jpg "title=" Qq20150905213854.png "alt=" Wkiom1xq7-3w6pedaaa970nklju055.jpg "/>
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/72/AD/wKiom1Xq9kWjNlAPAABLjB8N46I642.jpg "title=" Qq20150905220603.png "alt=" Wkiom1xq9kwjnlapaabljb8n46i642.jpg "/>
(4). In the client test
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/A8/wKioL1Xq8l-QKbTYAACpIjBq8IM786.jpg "title=" Qq20150905214018.png "alt=" Wkiol1xq8l-qkbtyaacpijbq8im786.jpg "/>
3. Experimental purpose: The binding of the IP address of the page and the binding of the port, restrict the users accessing the page.
(1) Nginx server side IP address is 192.168.1.10, when the user accesses the http://www.tarena.com displayed page as the default Nginx webpage, when the user accesses http://www.tarena.com:8090 The page that is displayed is/bbsdir,
(2) only 192.168.1.20 users are allowed access to http://www.tarena.com, which is inaccessible to everyone else.
Client Access Restrictions + user authentication
Deny client address denies client access
Allow client address allows client Access * default allows all clients to access
Client Address representation:
All client addresses, 192.168.1.1 an IP address, 192.168.1.0/24 network segment
(3) Users need to be authenticated to access the site.
(1) Modify Nginx master configuration file
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/AD/wKiom1Xq_sjAy2_5AAEWBGuVp7I479.jpg "title=" Qq20150905224218.png "alt=" Wkiom1xq_sjay2_5aaewbguvp7i479.jpg "/>
Client Testing
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/AD/wKiom1Xq_aCDmpvXAACOcDkOPgM903.jpg "title=" Qq20150905223730.png "alt=" Wkiom1xq_acdmpvxaacocdkopgm903.jpg "/>
(2) Modifying the master configuration file
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/72/A9/wKioL1XrB7yieECCAADB3h4xohM255.jpg "title=" Qq20150905231120.png "alt=" Wkiol1xrb7yieeccaadb3h4xohm255.jpg "/>
Testing on the client
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/A9/wKioL1XrB-7RyMZXAADCJ8NcmOs333.jpg "title=" Qq20150905230757.png "alt=" Wkiol1xrb-7rymzxaadcj8ncmos333.jpg "/>
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/72/A9/wKioL1XrB_igRcnzAADU_wODOfM168.jpg "title=" Qq20150905230927.png "alt=" Wkiol1xrb_igrcnzaadu_wodofm168.jpg "/>
(3) Modify the main configuration file Auth_basic user needs to enter the user name and password, auth_basic_user_file for the need to load user.txt files, User.txt is the user name and password.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/72/C2/wKiom1Xs2BWTDqIDAAGrK--iy1U444.jpg "title=" Qq20150907082125.png "alt=" Wkiom1xs2bwtdqidaagrk--iy1u444.jpg "/>
A package that generates a user name and password
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/72/C2/wKiom1XsyJWDT07lAABehTyl4wY142.jpg "title=" Qq20150907071536.png "alt=" Wkiom1xsyjwdt07laabehtyl4wy142.jpg "/>
Generate User name and password
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/72/C2/wKiom1XszBzxni_4AADZAcmNN4Y786.jpg "title=" Qq20150907073039.png "alt=" Wkiom1xszbzxni_4aadzacmnn4y786.jpg "/>
The client needs to have an image interface to open the browser input www.tarena.com will pop up a dialog box, you need to enter a user name and password
Experiment (III)
Experimental purpose: Smooth upgrade Nginx service (no stop service, online upgrade).
Unzip the 1.05 version of Nginx software and configure it.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/72/C2/wKiom1Xs0jjA7We2AALYDGqWSGE994.jpg "title=" Qq20150907075622.png "alt=" Wkiom1xs0jja7we2aalydgqwsge994.jpg "/>
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/BF/wKioL1Xs1JTTeE5DAADBd_jMh68330.jpg "title=" Qq20150907075735.png "alt=" Wkiol1xs1jttee5daadbd_jmh68330.jpg "/>
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/72/BF/wKioL1Xs1QrAfZb5AAF-64bQ9Tg951.jpg "title=" Qq20150907075933.png "alt=" Wkiol1xs1qrafzb5aaf-64bq9tg951.jpg "/>
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/72/BF/wKioL1Xs1Urz7ReTAAA_2Iw4nUc904.jpg "title=" Qq20150907075838.png "alt=" Wkiol1xs1urz7retaaa_2iw4nuc904.jpg "/>
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/72/C2/wKiom1Xs00WQXE6nAAGSmE3nhTA540.jpg "title=" Qq20150907080115.png "alt=" Wkiom1xs00wqxe6naagsme3nhta540.jpg "/>
Change/user/local/nginx/sbin/nginx to Nginx.old, put Nginx under current directory, user/local/nginx/sbin/
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/BF/wKioL1Xs1kzxVFjDAAEMsrs5O9M935.jpg "title=" Qq20150907080304.png "alt=" Wkiol1xs1kzxvfjdaaemsrs5o9m935.jpg "/>
Smooth upgrade Nginx Service
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/C2/wKiom1Xs16iwofMlAAIjPRUOlnI890.jpg "title=" Qq20150907081836.png "alt=" Wkiom1xs16iwofmlaaijpruolni890.jpg "/>
Experiment (IV)
Experimental purpose: The company is a video site has a lot of video files audio file picture files, in order to prevent others to link their own resources for their own profit, the company asked the site to prohibit others to link.
1. Modify the master configuration file
Location matches the URL address of the user, ~ represents the match, * represents the Ignore literal case, () represents the matching content, \ means the escape character is the point of the escape character, the $ represents the end of the valid_referers, and the value of the URL for the built-in variable is stored. There are 4 types of URL type (none is access without a network path, blocked represents the type of address that is converted through the firewall, the type of site hostname, and the region in which the site is located).
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/72/CB/wKioL1Xtb3exEANTAAKV4vZGgVI168.jpg "title=" Qq20150907185814.png "alt=" Wkiol1xtb3exeantaakv4vzggvi168.jpg "/>
2. Test the master configuration file for errors
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/CE/wKiom1XtbYCwvvZNAAEL5KQHnak410.jpg "title=" Qq20150907185920.png "alt=" Wkiom1xtbycwvvznaael5kqhnak410.jpg "/>
3. Restart the service
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/72/CE/wKiom1XtbfmxMohOAABz5H7TkWs548.jpg "title=" Qq20150907190119.png "alt=" Wkiom1xtbfmxmohoaabz5h7tkws548.jpg "/>
Summarize:
Domain name virtual host published to public network client access
IP Virtual Host + Port virtual host test or Post site Admin page
This article is from the "Down to earth" blog, make sure to keep this source http://343614597.blog.51cto.com/7056394/1692461
Nginx provides Web services applications including (virtual host, user access control, user authentication, Nginx smooth upgrade, anti-theft chain) configuration