Nginx User Guide

Source: Internet
Author: User

Nginx User Guide

1. Run nginx

You can run the nginx command to enable nginx:

nginx
If nginx is enabled, run the nginx command and add the-s parameter to control nginx running.
nginx -s signal
Signal Value:
Stop-Quick Close
Quit-elegant close
Reload-reload the configuration file reopen-re-open the log file

For example, you can use the following command to disable nginx after nginx finishes processing the current request.

nginx -s quit

After modifying the configuration file, run the following command:

nginx -s reload

2. Configure nginx

Open the configuration file, usually in/etc/nginx. cnf, depending on your own installation parameters.

Nginx. conf already contains a server block configuration case, but it is commented out. Below is the basic configuration of a server Block

http {    server {    }}

Server block, you can configure some locations to specify the local resources corresponding to the request url.

location / {    root /data/www;}
The above indicates that all access resources under/are under the/data/www folder.
location /images/ {    root /data;}
This indicates that all images accessed by the/images/path are under/data.

The preceding unified configuration is

server {    
listen 8080; 
Location/{root/data/www;} location/images/{root/data ;}}

If I access http: // localhost/images/example.png, nginx will return the example.png image under/data/images/in the file directory to the client.

If I access http: // localhost/some/example.html, nginx will return the example.html image under/data/www/in the file directory to the client.

Listen can be left unspecified. The default value is 8080.

If the configuration is modified during running

nginx -s reload

If the configuration is verified, but the specified file is not accessed as agreed, you can view the log file access under/usr/local/nginx/logs or/var/log/nginx. log and error. log

3. Configure reverse proxy

server {    location / {        proxy_pass http://localhost:8080;    }    location /images/ {        root /data;    }}

Proxy_pass specifies the reverse proxy path. All the paths that match the/will go to http: // localhost: 8080 to obtain resources.

For example, the resources accessed by http: // 192.168.1.100/some/example.html are actually resources obtained by http: // localhost/some/example.html, which are transparent to the client.

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.