In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to install and configure Nginx. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
1. Nginx installation and operation (Mac OS environment)
1. Install nginx
It can be installed directly through Homebrew:
$brew install nginx
After installation, the default home page file is in the / usr/local/var/www folder
The default profile address is / usr/local/etc/nginx/nginx.conf
Nginx uses port 8080 by default, and if you find that the port is occupied (check the port occupancy through $lsof-ikill 8080), you can kill the process using that port ($kill process PID). Or modify the default port of nginx (/ usr/local/etc/nginx/nginx.conf)
two。 Start nginx
$brew services start nginx
Or go to the directory / usr/local/bin $. / nginx
After the startup is successful, the browser accesses http://localhost:8080/ and you can see the static resources returned by the nginx server (resource / usr/local/var/www/index.html by default)
3. Stop nginx
$nginx-s stop
4. Restart nginx
$nginx-s reload
5. View nginx configuration path information
$brew info nginx II. Nginx rule configuration
More configurations can be viewed
Https://www.nginx.com/resources/wiki/start/#pre-canned-configurations
Http://nginx.org/en/docs/
Http://www.nginx.cn/doc/
1. Location
Location Grammar articles
2. Root and alias
In nginx, you can specify the access path to resources through root and alias.
1) root:
Location / {root / usr/local/var/www/; index index.html index.htm;}
The above rule: when requesting the address http://localhost:8080/index.html, the resources accessed are: / usr/local/var/www/index.html.
When requesting the address http://localhost:8080/test/a.png, the resource accessed is: / usr/local/var/www/test/a.png.
In other words, the address of the accessed resource is actually the path specified by root + the path to which location matches.
2) alias:
Alias is an alias, which is slightly different from the matching rules of root.
Location / a/ {alias / usr/local/var/www/b/;}
The above rule: when requesting the address http://localhost:8080/a/, the resources accessed are: / usr/local/var/www/b/index.html.
When requesting the address http://localhost:8080/a/1.gif, the resource accessed is: / usr/local/var/www/b/1.gif.
In other words, the resource address accessed is the path specified by alias and has nothing to do with the path matched by location (the path matched by location will be discarded).
3) the difference between root and alias:
Alias can only be used in location, while root can exist in server, http, and location.
Alias must end with "/", otherwise the file will not be found, and root is optional to "/".
3. Try_file
Location / test/ {try_files $uri $uri/ / a Universe 1.png;}
Try_files tries to read the files accessed by the user in the website directory, and returns directly if the first variable exists; if it does not exist, it continues to read the second variable, and if it exists, it returns directly; if it does not exist, it jumps to the third parameter.
Uri is a variable of nginx that holds the address accessed by the user. For example, to visit http://www.xxx.com/index.html,\ $uri is / index.html.
$uri/ represents access to a directory, such as http://www.xxx.com/hello/test/, so\ $uri/ is / hello/test/.
For example, the above rule: when requesting the address of http://localhost:8080/test/2.png, try_files will determine whether it is a file or a directory, only to find that it is a file, which matches the first parameter $uri variable. Then go to the website directory to find out if the test/2.png file exists, and if so, read it back directly. If it does not exist, jump to the third parameter, which returns the site root + / a/1.png file (/ usr/local/var/www/a/1.png).
More usage: https://www.jb51.net/article/156899.htm
4. Rewrite
Rewrite syntax
The rewrite function is to implement url rewriting and redirection.
Syntax rewrite regex replacement [flag]
Rewrite can only be placed in server {}, location {}, if {}, and can only work on strings after the domain name except for the passed parameters. For example, http://www.xxx.com/a/b/index.html?param=1&u=str only overrides / a/b/index.html.
The order in which rewrite is executed:
Execute rewrite instructions for server blocks
Perform location matching
Execute the rewrite instruction in the selected location
Flag flag bit:
Last: equivalent to the [L] tag of Apache, indicating that the rewrite is complete
Break: stops executing the subsequent rewrite instruction set of the current virtual host
Redirect: returns 302 temporary redirection. The address bar will display the address after the jump.
Permanent: returns 301 permanent redirection, and the address bar will display the address after the jump.
Location / home/ {rewrite ^ / home/test/ http://www.baidu.com;}
The above rule: when you visit the address of http://localhost:8080/home/test/, the page will be redirected to http://www.baidu.com.
Some little tips:
How can nginx redirect url without changing the display of url in the browser?
Proxy_pass can specify reverse proxy
More usage: https://www.jb51.net/article/134233.htm
Third, some command line configuration (mac OS)
1. How to open a file with vscode on the command line
Cd / usr/local/bin/ln-s "/ Applications/Visual Studio Code.app/Contents/MacOS/Electron" vscode
Where / Applications/Visual Studio Code.app/Contents/MacOS/Electron is the executable file of vscode, and the ln-s command puts it into the / usr/local/bin/ directory through a soft connection. This allows you to open the file with the vscode command elsewhere on the command line.
This is the end of this article on "how to install and configure Nginx". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, please share it out for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.