【nginx】nginx的安裝及測試


  

  nginx中文文檔:http://www.nginx.cn/doc/index.html

 

1.到官網下載nginx的壓縮包:

https://nginx.org/ 

 

 2.解壓到相應的目錄,比如我是e盤 然后修改目錄名字為nginx,進入nginx目錄 雙擊nginx.exe 來啟動nginx

 

注意:啟動的時候發現80端口被占用

  windows檢測80端口

netstat -ano | findstr 80
或者
netstat -ano | grep 80

 

然后查看占用的應用:(發現是tomcat占用80端口)

 

3.殺死tomcat后啟動nginx

(1)cmd窗口查看nginx是否啟動成功

 

(2)瀏覽器輸入localhost

 (3)寫一個簡單的html頁面放到nginx的安裝目錄的html下

訪問測試:

4. nginx代理發布靜態頁面

比如說我們想代理一個靜態項目:

(1)打開nginx/conf/nginx.conf,在最后的 } 前面增加如下:

 include vhost/*.conf;

表示引入 當前目錄/vhost/  下面所有后綴為conf的文件。

(2)接下來在當前conf目錄創建vhost目錄,並在下面創建test.conf文件,內容如下:

server {
    listen 80 default_server;
    root    C:/Users/Administrator/Desktop/test;
}

 

  root指定靜態目錄的頁面.目錄分割符號必須是 / 

(3)檢查語法或者重加載

nginx.exe -t #檢查語法
nginx: the configuration file E:\nginx\nginx-1.14.2/conf/nginx.conf syntax is ok
nginx: configuration file E:\nginx\nginx-1.14.2/conf/nginx.conf test is successful

 

nginx.exe -s reload  #重新加載配置

 

nginx.exe -s reopen #重啟
nginx.exe -s stop    #停止

 

(4)測試:

(5)配置文件也可以指定404錯誤頁面:(會定位到 C:/Users/Administrator/Desktop/test/404.html 頁面  )

server {
    listen 80 default_server;
    root    C:/Users/Administrator/Desktop/test;
    
    error_page 404 = /404.html; 
}

 

  nginx配置也可以對響應頭增加對應的響應頭等。

 

關於請求代理可以參考:https://www.cnblogs.com/qlqwjy/p/11909165.html

 

關於linux安裝nginx參考:https://www.runoob.com/linux/nginx-install-setup.html

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM