1.前提準(zhǔn)備
安裝編譯工具及庫文件
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel pcre-devel
gcc、gcc-c++ # 主要用來進(jìn)行編譯相關(guān)使用
openssl、openssl-devel # 一般當(dāng)配置https服務(wù)的時候就需要這個了
zlib、zlib-devel # 主要用于文件的解壓縮
pcre、pcre-devel # Nginx的rewrite模塊和HTTP核心模塊會用到PCRE正則表達(dá)式語法
make # 遍歷
make install # 安裝
2.下載解壓nginx
cd /usr/local/ngin
// wget https://nginx.org/download/nginx-1.18.0.tar.gz #下載(有了就不用下載)
tar -zxvf nginx-1.18.0.tar.gz #解壓
或者nginx下載地址:http://nginx.org/download/ (將下載的nginx導(dǎo)入到服務(wù)器中)
進(jìn)入安裝包目錄
cd nginx-1.9.9
編譯安裝nginx,默認(rèn)安裝到 /usr/local/nginx中
//編譯
./configure --prefix=/usr/local/nginx
//安裝
make && make install
先找一下nginx安裝到什么位置上了
[root@localhost nginx-1.9.9]# whereis nginx
nginx: /usr/local/nginx
3.配置和驗證
在nginx.conf中簡單配置
server {
listen 80;
server_name localhost;
location / {
root /usr/local/web/dist;
index index.html index.htm;
}
# 靜態(tài)資源目錄,在對應(yīng)目錄先建好文件夾
location /admintest {
alias /usr/local/web/admin/dist;
index index.html index.htm;
}
#代理node服務(wù)
location /api {
proxy_pass http://127.0.0.1:3002;
}
}
同一ip配置多個域名
server{
listen 80;
server_name www.aaa.com; #綁定域名
index index.htm index.html index.php; #默認(rèn)文件
root /home/web/dist; #網(wǎng)站根目錄
error_page 404 /404.html;#添加404網(wǎng)頁
}
server{
listen 80;
server_name www.bbb.com; #綁定域名
index index.htm index.html index.php; #默認(rèn)文件
root /home/web/dist1; #網(wǎng)站根目錄
}
#不帶www的域名加301跳轉(zhuǎn)
server{
listen 80;
server_name bbb.com;
rewrite ^/(.*) http://www.bbb.com/$1 permanent;
}
查看nginx.conf配置是否正確
/usr/local/nginx/sbin/nginx -t
[root@localhost sbin]# /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
cd /usr/local/nginx/sbin/
./nginx #啟動
./nginx -s stop #停止
./nginx -s quit #退出
./nginx -s reload #重啟 修改配置后重新加載生效<br><br>./nginx -s reopen :重新打開日志文件<br>
啟動后查看進(jìn)程
kill -QUIT 主進(jìn)程號 #從容停止
kill -TERM 主進(jìn)程號 #快速停止
kill -9 主進(jìn)程號 #強(qiáng)制停止
問題
我們Linux系統(tǒng)在安裝應(yīng)用程序時進(jìn)行指定其安裝目錄 ,通常使用 ./configure --prefix=自定義的安裝目錄 命令來操作。
例如我安裝python應(yīng)用使用
./configure --prefix=/home/softwareInstall/pythoninstall
錯誤提示:./configure報
-bash: ./configure: No such file or directory
分析原因:
1、在你配置指定路徑時沒有這樣的文件或目錄存在,先創(chuàng)建一個目錄。
2、可能現(xiàn)在執(zhí)行的目錄下沒有configure 程序,你無法執(zhí)行,你到configure所在目錄下重新執(zhí)行語句就可以了