Download and install nginx in windows, configure environment variables and use nginx globally. However, when using nginx, the conf path is found according to the relative path
nginx -VI can see it. In this case, after you enter the CMD, you have toStart nginx (or other command options to control nginx), you must switch to the directory where nginx is located, or specify the absolute path of the conf path at startup, or recompile nginx to specify the conf path (it’s very convenient in Linux, and it’s also possible in win)CMD will report an errorNginx cannot be started. This is not comfortable to use. After all, you have to type a long string of path characters: (. Because I didn’t want to recompile, I thought of another way——Using bat file。
- You need to configure environment variables to use nginx globally
- In the command options of nginx, except for the start stop reload command of the configuration file, which will report an error when used in a non installation path (as mentioned in the preface), the others can be used directly. For example, nginx – V view version
Create a bat file (mine is nginxd. Bat) and use bat to run the nginx command. Once created, you can use the following command:
`nginxd [-h,help] [-v,version] [start] [stop] [stop -a] [reload] [reopen] [find]` * 1
Use nginxd – h to check. Of course, the nginxd command depends on the bat file name. The file location is arbitrary, but it should be able to be used globally (i.e. specify environment variables). The code is as follows:
`@echo off if "%1"=="help" (goto help) else (if "%1"=="-h" goto help) if "%1"=="version" (goto version) else (if "%1"=="-v" goto version) if "%1"=="start" goto start if "%1"=="stop" goto stop if "%1"=="reload" goto reloadmd if "%1"=="reopen" goto reopen if "%1"=="find" goto find goto error :help nginx -v echo Usage: nginxd [-h,help] [-v,version] [start] [stop] [stop -a] [reload] [reopen] [find] echo= echo Options: echo help,-h : this help echo version,-v : show current nginx version echo start : start nginx master process echo stop : stop the newest nginx master process echo stop -a : stop all nginx master processes echo reload : reload configuration echo reopen : reopen nginx echo find : show the nginx master process list echo= exit /B :version nginx -v exit /B :start start nginx -p D:Softwarenginx exit /B :stop if "%2"=="-a" (taskkill /F /IM nginx.exe) else (if "%2"=="" (nginx -s stop -p D:Softwarenginx) else goto error) exit /B :reload nginx -s reload -p D:Softwarenginx exit /B :find tasklist /fi "imagename eq nginx.exe" exit /B :error echo nginxd: invalid option: "%1 %2" echo= exit /B`
This is for Xiaobai. Of course, there are better ways to achieve it. I’m just in touch with it. Please understand the shortcomings. In addition, the following is my own understanding, there may be differences, please forgive me
- @echo off：This command is divided into @ and echo [email protected] Let the following command execution process not print out, echo off let all the command execution process not print out (test yourself, see the results).
- Goto and
::The two commands are used together,
:Equivalent to a tag, goto specifies to jump after that tag.
- echo: prints a specified line of characters to the command window,
echo=Print an empty string and the result is equivalent to a newline.
- exit：The command is to exit the program and close the command window (which is not what I want). appoint
/BThe window will not be closed after exiting the program/ B means to go back to the previous command window.