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.