NGINX是一個高性能的HTTP和反向代理伺服器,它可以運行在多個操作系統上,包括Linux和Windows。這篇文章將會介紹如何在Windows操作系統上安裝NGINX伺服器。
一、下載NGINX
首先,在官網(https://nginx.org/en/download.html)上下載Windows版本的NGINX。在下載頁面中,選擇最新的穩定版本的Windows版本並下載,下載完畢後解壓到任意一個目錄。
例如,下載後的文件解壓至C:\nginx\,這個文件夾下將會包含各種NGINX所需的文件。
二、配置NGINX
在安裝過程中,不需要對NGINX進行配置,但是我們可以進行一些基本的配置以確保其能夠正確運行。
在C:\nginx\下,找到「conf」文件夾,並且右鍵單擊「nginx.conf」,選擇「編輯」以編輯此文件。
在編輯器中,找到以下代碼:
# Windows directory support # Win32 will sense this from the environment variable. # # path names: # - for 'url' we'll convert them to forward slashes # - for file-path 'alias' or 'root' we'll need to be careful # to use backslashes and not forward slashes. # #root html; #access_log logs/host.access.log main; #error_log logs/host.error.log;
將其中的「root html;」改為「root html;」,這將設置您的NGINX伺服器的默認文檔根目錄。
接下來,在同一個文件中,找到以下代碼:
#error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid;
在這個代碼段中,取消注釋「error_log logs/error.log;」和「pid logs/nginx.pid;」,以便在出現錯誤時可以輕鬆找到日誌文件,並且可以讓NGINX伺服器進程的進程ID號能夠被捕捉。
三、運行NGINX
啟動NGINX伺服器可以通過進入解壓後的文件夾並且執行以下命令:
nginx.exe
您將看到類似以下的輸入:
C:\nginx>nginx.exe nginx: the configuration file C:\nginx/conf/nginx.conf syntax is ok nginx: configuration file C:\nginx/conf/nginx.conf test is successful nginx: nginx.exe has been started successfully.
現在,您的NGINX伺服器已經在Windows上正確運行,並且您可以在瀏覽器中訪問http://localhost來訪問該伺服器。
四、啟動和關閉伺服器
要停止NGINX伺服器,請在解壓後的文件夾中執行以下命令:
nginx.exe -s stop
這將使NGINX伺服器停止運行,您可以在瀏覽器中無法訪問該伺服器。
如果您需要重新啟動該伺服器,請執行以下命令:
nginx.exe
您將看到類似以下的輸入:
C:\nginx>nginx.exe nginx: the configuration file C:\nginx/conf/nginx.conf syntax is ok nginx: configuration file C:\nginx/conf/nginx.conf test is successful nginx: the configuration file C:\nginx/conf/nginx.conf was found correct nginx: nginx.exe has been started successfully.
現在,您的NGINX伺服器又開始運作了。
五、總結
NGINX是一個易於安裝和配置的HTTP和反向代理伺服器,您可以在Windows上輕鬆地安裝它。在此文章中,我們介紹了如何下載和安裝NGINX,並且介紹了如何進行一些基本配置以使其能夠正確運行。我們還演示了如何啟動和關閉伺服器,以及如何重新啟動它。
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/239505.html