文章目錄
- 一. Nginx安裝
- 二. nginx其他相關指令
- 三. 外網通路
一. Nginx安裝
官網下載下傳Nginx: https://nginx.org/en/download.html

下載下傳後, 将壓縮包放到Linux系統中.
可以使用xftp工具或者rz指令
然後就是解壓,安裝
# 解壓
$ tar -zvxf nginx-1.18.0.tar.gz
$ cd nginx-1.18.0
$ ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_addition_module --with-http_flv_module --with-http_gzip_static_module --with-http_realip_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_dav_module
# 編譯安裝
$ make&&make install
檢驗是否安裝成功
$cd /usr/local/nginx/sbin
$ ./nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
如果報這個錯誤:
nginx: [emerg] getpwnam("nginx") failed in /usr/local/nginx/conf/nginx.conf
解決方法:
編輯
這個檔案, 将
/usr/local/nginx/conf/nginx.conf
這個注釋去掉.
user nobody
![]()
Linux安裝Nginx - Linux 參考:
nginx重新開機報錯: [emerg] getpwnam(“www”) failed…
二. nginx其他相關指令
# 啟動
$ ./nginx
# 停止
$ ./nginx -s stop
# 重新啟動
$ ./nginx -s reload
# 檢視nginx是否啟動成功
$ ps -ef|grep nginx
啟動時, 首先要確定系統的80端口是否占用
# 檢視端口是否占用$ netstat -ano|grep 80
如果占用則需要到
檔案中修改啟動端口.
/usr/local/nginx/conf/nginx.conf
![]()
Linux安裝Nginx - Linux
三. 外網通路
# 對外開放通路的端口
$ firewall-cmd --add-port=端口号/tcp --permanent
# 重新加載防火牆設定
$ firewall-cmd --reload
# 檢視已經開放的端口号
$ firewall-cmd --list-all
- nginx安裝/配置/測試 - 簡書