當前位置:首頁 » 操作系統 » linux下的nginx

linux下的nginx

發布時間: 2022-05-21 13:50:00

1. linux下nginx怎麼使用

第一步:從http://nginx.org/download/上下載相應的版本(或者wget http://nginx.org/download/nginx-1.5.9.tar.gz直接在Linux上用命令下載)
第二步:解壓 tar -zxvf nginx-1.5.9.tar.gz
第三步:設置一下配置信息 ./configure --prefix=/usr/local/nginx ,或者不執行此步,直接默認配置
第四步:make 編譯 (make的過程是把各種語言寫的源碼文件,變成可執行文件和各種庫文件)make install 安裝 (make install是把這些編譯出來的可執行文件和庫文件復制到合適的地方)

2. 如何在linux下搭建nginx伺服器

1、下載後解壓nginx

tar -zxvf nginx-1.4.7.tar.gz
2、安裝gcc等依賴包
yum -y install gcc pcre-devel openssl openssl-devel
3、開始安裝nginx
cd進入nginx-1.4.7目錄內
./configure 編譯
make&&make install 這一步需要先cd出來嗎?在裡面會安裝失敗嗎?我忘了 = =
4、此時就已經安裝完成,默認安裝在了/usr/local/nginx/sbin/nginx
5、啟動
命令行輸入/usr/local/nginx/sbin/nginx,沒反應
輸入ps -ef | grep nginx查看nginx進程
6、測試
命令行輸入 curl http://127.0.0.1
會出現welcome to nginx之類的就說明對了!
7、加入到環境變數
vim /etc/profile
尾行添加
PATH=$PATH:/usr/local/nginx/sbin
export PATH
保存關閉後運行 source /etc/profile 即會加入環境變數
8、常用命令
[root@ usr]# nginx -s stop停止nginx
[root@ usr]# nginx 運行nginx
[root@ usr]# nginx -s reload 重啟nginx
[root@ usr]# nginx -t 測試nginx
9、防火牆允許外網訪問
vim /etc/sysconfig/iptables
添加過濾規則
-A -INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
好像是保存後即時生效把?
service iptables stop
service iptables start
重啟服務後還是會生效,親測
10、修改網站默認根目錄路徑
網站默認根目錄放在/usr/local/nginx/html
命令行輸入 vim /usr/local/nginx/conf/nginx.conf
找到改為
server {
listen 80;
server_name localhost;
root /var/www/html/default;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
# root html;
index index.html index.htm;
}
注釋掉下面的,在上面添加自己想要的根目錄,重啟nginx才能生效。

3. 如何查看linux 下 nginx配置

默認的路徑是你安裝時候指定的
如果用的lnmp之類的安裝包
你可以在shell下
whereisnginx
找到相應的路徑之後
在nginx下的conf文件夾里看配置文件,日誌文件如果記錄了話
在配置文件里有路徑的~

4. linux中啟動Nginx

nginx的啟動命令是:
/usr/local/nginx/sbin/nginx
-c
/usr/local/nginx/conf/nginx.conf
-c制定配置文件的路徑,不加-nginx會自動載入默認路徑的配置文件。
以上是通用的啟動命令

5. 如何在linux下編譯nginx

安裝nginx
1.下載
2.解壓
復制代碼代碼如下:
tar
-zxvf
nginx-1.7.0.tar.gz
3.編譯和安裝
執行如下命令:
# cd nginx-1.7.0# ./configure --prefix=/usr/local/nginx-1.7.0 \--with-http_ssl_mole --with-http_spdy_mole \--with-http_stub_status_mole --with-pcre
–with-http_stub_status_mole:支持nginx狀態查詢–with-http_ssl_mole:支持https–with-http_spdy_mole:支持google的spdy,想了解請網路spdy,這個必須有ssl的支持–with-pcre:為了支持rewrite重寫功能,必須制定pcre最後輸出如下內容,表示configure
OK了。

6. linux 下nginx模塊的安裝

安裝

第一步 下載並解壓Nginx壓縮

從Nginx官網下載Nginx,或者在Linux上執行wget http://nginx.org/download/nginx-1.10.1.tar.gz命令直接下載
解壓nginx-1.10.1.tar.gz文件:

tar zxvf nginx-1.10.1.tar.gz
1
1
第二步 配置

cd nginx-1.10.1
./configure --prefix=/usr/local/nginx
1
2
1
2
注意:
① 如果之前沒有安裝C compiler(C 編譯器),這一步將報如下錯誤信息:

xueliang@dev:~/download/nginx-1.10.1$ ./configure –prefix=/usr/local/nginx
checking for OS
+ Linux 4.2.0-27-generic x86_64
checking for C compiler … not found

./configure: error: C compiler cc is not found

xueliang@dev:~/download/nginx-1.10.1$
可以參考這篇文章安裝C compiler,然後繼續下面的操作

② 如果之前沒有安裝PCRE,這一步將報如下錯誤信息:

checking for PCRE library … not found
checking for PCRE library in /usr/local/ … not found
checking for PCRE library in /usr/include/pcre/ … not found
checking for PCRE library in /usr/pkg/ … not found
checking for PCRE library in /opt/local/ … not found

./configure: error: the HTTP rewrite mole requires the PCRE library.
You can either disable the mole by using –without-http_rewrite_mole
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using –with-pcre= option.

xueliang@dev:~/download/nginx-1.10.1$

③ 如果之前沒有安裝zlib,這一步將報如下錯誤信息:

checking for md5 in system md library … not found
checking for md5 in system md5 library … not found
checking for md5 in system OpenSSL crypto library … not found
checking for sha1 in system md library … not found
checking for sha1 in system OpenSSL crypto library … not found
checking for zlib library … not found

./configure: error: the HTTP gzip mole requires the zlib library.
You can either disable the mole by using –without-http_gzip_mole
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using –with-zlib= option.

xueliang@dev:~/download/nginx-1.10.1$

也可以跳過此步,執行默認安裝,--prefix的默認值為/usr/local/nginx,Nginx官網對此有說明:Building nginx from Sources

7. 啟動nginx命令linux下

方法1:找到nginx的路徑和nginx配置文件的路徑,然後運行
/usr/具體路徑/nginx -c /usr/具體路徑/nginx.conf
方法2:找到nginx路徑
工作目錄切換到nginx下:cd /usr/具體路徑/sbin
然後運行nginx軟體: ./nginx

8. linux下nginx一直殺不完是什麼原因

nginx的進程分為Master進程和worker進程,worker進程是Master派生出來的子進程,其數量始終維持在一個數量上,當缺少一個worker進程是,Master就會派生一個新的子進程。所以你殺worker進程是殺不完的。
可以這樣做:
kill `pgrep -o nginx`
解釋一下:
pgrep -o nginx 查看第一個啟動的進程號,一般就是主進程號了。
kill `pgrep -o nginx` 等價於 kill 主進程號。

9. linux下如何重啟nginx

1、第一種方法:首先在進入nginx可執行目錄bin,輸入代碼:cd /usr/local/nglnx/sbln。

10. linux系統怎麼安裝nginx

這里以CentOS6.6系統(32位)中安裝nginx的源碼包,進行講解。
1. nginx源碼包的下載
nginx官方下載地址:http://nginx.org/
選擇你要安裝的nginx版本,這里,我選擇的是 nginx-1.10.2 。
具體的下載鏈接為:http://nginx.org/download/nginx-1.10.2.tar.gz
可以在其他電腦下載好,通過ftp軟體傳給要安裝的linux電腦。也可以直接在linux電腦上使用wget命令下載。這里我們使用後一種方式。
在linux的根目錄,創建一個多級空目錄 /my_package/source,用來存放下載的源碼包。
mkdir -p /my_package/sourcecd /my_package/source12

執行下載命令:
wget http://nginx.org/download/nginx-1.10.2.tar.gz1

下載完成後,在 /my_package/source 目錄中,就有了 nginx-1.10.2.tar.gz 源碼包壓縮文件。
2. nginx的安裝與配置
2.1 准備工作
安裝nginx之前,需要先安裝pcre庫。如果你的linux系統中沒有pcre,需要先進行安裝。
這里,我們使用yum工具,在線快速安裝pcre:
yum -y install pcre
yum -y install pcre-devel12

可以通過下面的命令,找到已安裝的pcre和pcre-devel的位置:
rpm -ql pcre
rpm -ql pcre-devel或
find / -name "*pcre*"1234

2.2 nginx的安裝
配置nginx安裝的參數,比如:安裝路徑,指定依賴庫的具體位置等。
這里我們使用默認安裝配置:
tar -zxvf nginx-1.10.2.tar.gzcd nginx-1.10.2./configure123

如果這一步執行正確,在提示信息中會告知nginx將要安裝的位置、可執行文件的位置等,如下:
nginx path prefix: "/usr/local/nginx"nginx binary file: "/usr/local/nginx/sbin/nginx"nginx moles path: "/usr/local/nginx/moles"nginx configuration prefix: "/usr/local/nginx/conf"nginx configuration file: "/usr/local/nginx/conf/nginx.conf"nginx pid file: "/usr/local/nginx/logs/nginx.pid"nginx error log file: "/usr/local/nginx/logs/error.log"nginx http access log file: "/usr/local/nginx/logs/access.log"nginx http client request body temporary files: "client_body_temp"nginx http proxy temporary files: "proxy_temp"nginx http fastcgi temporary files: "fastcgi_temp"nginx http uwsgi temporary files: "uwsgi_temp"nginx http scgi temporary files: "scgi_temp"12345678910111213

如果這一步出錯了,根據錯誤提示信息解決問題後,使用 make clean 命令,清除產生的臨時文件,再來重新執行 ./configure
如果想查看具體可以配置哪些安裝參數,可以使用下面的命令查看:
./configure --help1

編譯和安裝
makemake install12

到此,nginx的源碼包就安裝完畢了。
2.3 nginx的配置
如果想修改nginx的配置文件,可使用下面的命令:
vi /usr/local/nginx/conf/nginx.conf1

3. nginx的常用命令
檢查測試nginx的配置信息是否正確
/usr/local/nginx/sbin/nginx -t1

啟動nginx
/usr/local/nginx/sbin/nginx1

啟動nginx伺服器後,可以使用下面的命令檢測nginx是否啟動成功,並查看nginx的埠、主進程號、進程名稱等信息。
netstat -tlunp1

也可以使用下面的命令檢測nginx是否啟動成功,並查看nginx的主進程和子進程的詳細信息。
ps aux | grep nginx1

ps aux 命令(a代表前台進程,x代表後台進程,u代表進程的發起者)列出的進程信息中,主要包含以下信息:USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND 。這里,簡單說明一下:
USER:表示進程的發起者,也就是說,進程是哪個用戶產生的。
PID:表示進程的id,也稱作,進程號。%CPU:表示進程佔用的CPU資源的百分比。%MEM:表示進程佔用的物理內存的百分比。
VSZ:表示進程佔用的虛擬內存的大小,單位KB。
RSS:表示進程佔用的實際物理內存的大小,單位KB。
TTY:表示進程是在哪個終端中運行的。其中tty1到tty7代表本地控制台終端,tty1到tty6是本地的字元界面終端,tty7是圖形終端。pts/0-255代表虛擬終端(即遠程登錄終端)。
STAT:表示進程的狀態。常見的狀態有:R 運行;S 睡眠;T 停止;s 包含子進程;+ 位於後台。
START:表示進程是在什麼時間啟動的。
TIME:表示進程佔用CPU的運算時間,值越大,越耗費資源。
COMMAND:表示產生該進程的命令(通過它可以識別正在運行的進程名)。1234567891011

成功啟動nginx後,就可以在本地電腦或其他電腦中訪問你的nginx伺服器中的網站了。
本地電腦(即nginx所在的電腦)的訪問方式:curl 127.0.0.1
其他電腦(區域網內)的訪問方式:打開瀏覽器,輸入nginx伺服器的區域網IP即可。12

為了更方便的使用 /usr/local/nginx/sbin 中的命令,
我們將其加入linux系統的環境變數,即修改文件 /etc/profile,在最後加入下面的代碼:
export PATH="/usr/local/nginx/sbin:$PATH"1

保存退出後,執行命令:source /etc/profile 可使該配置文件立即生效。
關閉nginx
nginx -s stop 快速關閉nginx
nginx -s quit 平滑關閉nginx
kill -s QUIT 11247 通過linux的kill命令殺死nginx進程,11247為nginx的主進程號123

重新載入nginx的配置文件
nginx -s reload 修改了nginx的配置文件後,可以使用該命令讓新的配置立即生效,而不用重啟整個nginx伺服器

希望我的方法能夠幫助到你

熱點內容
快存儲組件 發布:2024-10-26 01:25:43 瀏覽:846
電腦內存不夠租用伺服器 發布:2024-10-26 01:19:03 瀏覽:598
氟壓縮機房 發布:2024-10-26 01:09:45 瀏覽:405
httpurlconnection緩存 發布:2024-10-26 01:04:24 瀏覽:810
三星手機鎖屏怎麼設置密碼 發布:2024-10-26 01:00:35 瀏覽:847
計劃排程演算法 發布:2024-10-26 00:48:08 瀏覽:8
網站伺服器搭建與管理實訓報告 發布:2024-10-26 00:30:56 瀏覽:746
秦遙控駕駛是哪個配置 發布:2024-10-26 00:25:48 瀏覽:848
神鵰俠侶伺服器連接超時怎麼回事 發布:2024-10-26 00:25:28 瀏覽:381
11系統如何安裝安卓應用 發布:2024-10-26 00:22:40 瀏覽:713