No time – Nginx environment setup
After such a long time, HERE I am again. Have you missed me?
Xiao Hong: Sorry, I didn’t miss you
Xiao Qian: Brother, I miss you…
I: Small money, no, you don’t
What is nginx? What about Nginx? The first thing that comes to mind is that this guy is a Web server, or that this guy is a middleman, responsible for forwarding tasks, just like delivery…
You said, look at the source code, not debugging, is not read (not I said…). Actually, I’m trying to be funny here… On second thought, let it go. Let it go.
Without further ado, let’s get started.
The premise
The environment I use:
- macos
- Vscode: I used to prefer large ides like IDEA, Goland, but now I use lightweight editors…
- Github: Why is there this? Of course it is used to download the code……
- Nginx: The current code is said to be up to 160,000 lines of code, but for such a large project it is advisable to pull the early source code
Try a knife to cattle
See why I’m being funny again? Well, you get the idea
- Github -nginx-0.5
- In the early versions, most of the core code and core design ideas are worth learning and thinking about
- Next unzip the project code and open it with vscode
- Then edit
auto/cc/conf
The file will bengx_compile_opt="-c"
Modified tongx_compile_opt="-c -g"
- Next we use the following configure command
Sudo./auto/configure --prefix= create a new directory for your nginx // ~/Documents/mybook/nginx sudo ./auto/configure --prefix=~/Documents/mybook/nginxCopy the code
Note here: If a problem like “The HTTP rewrite Module requires the PCRE library” occurs, the solution is brew install PCRE
Because compiling nginx’s dependent libraries:
- pcre
- openssl
- zlib
www.cmdschool.org/archives/10…
- Proceed with the following command:
sudo make
sudo make install
Copy the code
- After executing, you can see the structure of the previous directory:
cd ~/Doucments/mybook/nginx
.├ ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── Default │ ├─ Koi-UTF │ ├─ mime.types │ ├─ mime.types. Default │ ├─ Nginx.conf // Default │ ├─ Scgi_Params │ ├─ Scgi_Params. Default │ ├─ UWSGI_Params │ ├─ ├── ├─ ├─ ├─ uWSgi_exercises. Default │ ├── ├─ ├─ access.log │ ├─ uWSgi_exercises . └ ─ ─ the error log ├ ─ ─ proxy_temp ├ ─ ─ sbin │ └ ─ ─ nginx / / main program ├ ─ ─ scgi_temp └ ─ ─ uwsgi_tempCopy the code
- Part of the climax comes when the terminal exits the directory and switches to the directory that vscode opened earlier
./objs/nginx
Copy the code
Sudo chmod -r 755 XXX sudo chmod -r 755 XXX
- Open your browser and enter:
127.0.0.1
, you can see the result of the rendering below
- Before exiting the nginx process, of course, I want you to see one thing. Terminal type:
ps aux | grep "nginx"
Copy the code
Well, you’ve got the idea… Since understand, that I will skip ha…
- Come on, we’re getting out of this thing. You can choose to be violent, or you can choose to be elegant.
- Be violent:
kill -9
It’s too violent. I won’t hide it - Be elegant:
./objs/nginx -s stop
- Be violent:
Here’s a list of the guy’s most common commands:
#Windows startup
> start nginx
#Linux/MAC
$ service nginx start
#Manually specify the configuration
$ nginx -c /usr/local/nginx/conf/nginx.conf
#-p Specifies the nginx run directory (log storage location).
$ nginx -c /path/nginx.conf -p /path/
#restart
$ nginx -s reload
#Shut down
$ nginx -s stop
#Check the port
$Netstat - an | grep port# Linux/MAC system
>Netstat - an | findstr searches port# Windows
#Testing the Web service
$Curl -i host: port
#or
$Telnet host port
#Check the process
$ ps -ef | grep nginx
#Viewing error Logs
$ tail -30 /var/log/nginx/error.log
Copy the code
- We debug later, can’t let it guard the process? Okay, let’s change his configuration…
Didn’t we just list a bunch of file trees? Isn’t there an nginx.conf file in there? Come on, show:
Add a line of magic code to this file:
daemon off;
Copy the code
- At this point, we can execute at the terminal
./objs/nginx
Good. This guy’s kind of stuck. Isn’t that what we want? Laying the groundwork for debugging…
Artifact. – Debug you
Note: I use VScode editor, of course not afraid of your jokes, for several years I have not used C and C ++, these two years the language is Java and Golang and Python (you understand)
After all, the nginx code is written in c and c++, so we need to install a plug-in on vscode:
Understand all understand, do not understand is also can be forced to understand, I will not repeat
If the installation process, there is a small problem, so please Google search to solve it, use Google…
Json will be created in the root directory, but you can also create it by clicking the debug button next to it
The configuration of this file is:
{
// Use IntelliSense to learn about related attributes.
// Hover to view descriptions of existing properties.
/ / for more information, please visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0"."configurations": [{"name": "(LLDB) start"."type": "cppdbg"."request": "launch"."program": "${workspaceFolder}/objs/nginx"."args": []."stopAtEntry": true."cwd": "${workspaceFolder}"."environment": []."externalConsole": true."MIMode": "lldb"}}]Copy the code
Next, make a breakpoint in SRC /core/nginx.c
Then we can debug as much as we like…
conclusion
- So long again…
- More pictures…
- If you think it’s very simple, please call me if you have any questions
reference
- Github.com/nginx/nginx…
- zhuanlan.zhihu.com/p/47236996
- Segmentfault.com/a/119000001…