Linux安裝Nginx及配置nginx.conf方式
更新時間:2024年10月10日 10:43:00 作者:思祺班
本文提供了在Linux系統(tǒng)上安裝Nginx和配置nginx.conf的詳細(xì)步驟,為初學(xué)者提供了便捷的操作指導(dǎo)和個人經(jīng)驗(yàn)分享,適合需要搭建服務(wù)器的用戶參考
Linux安裝Nginx及配置nginx.conf
操作如下
**一鍵安裝上面四個依賴** yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel **創(chuàng)建一個文件夾** cd /usr/local mkdir nginx cd nginx **下載tar包** wget http://nginx.org/download/nginx-1.13.7.tar.gz **解壓tar** tar -xvf nginx-1.13.7.tar.gz **進(jìn)入nginx目錄** cd /usr/local/nginx **進(jìn)入目錄** cd nginx-1.13.7 **執(zhí)行命令 考慮到后續(xù)安裝ssl證書 添加兩個模塊** ./configure --with-http_stub_status_module --with-http_ssl_module **執(zhí)行make命令** make **執(zhí)行make install命令** make install **啟動nginx服務(wù)** /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf **打開配置文件** vi /usr/local/nginx/conf/nginx.conf * *配置nginx.conf在下面 * **配置完后 重啟nginx** /usr/local/nginx/sbin/nginx -s reload **可以看一下Nginx是否啟動** ps -ef | grep nginx ###相關(guān)命令 安裝完成一般常用命令 進(jìn)入安裝目錄中, 命令: cd /usr/local/nginx/sbin 啟動,關(guān)閉,重啟,命令: ./nginx 啟動 ./nginx -s stop 關(guān)閉 ./nginx -s reload 重啟
注意下面的文字說明
#第一步改這個 改為root user root; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; #vue項目的打包后的dist自己放的前端項目位置 root /www/jinghui/dist/; location /{ try_files $uri $uri/ @router;#需要指向下面的@router否則會出現(xiàn)vue的路由在nginx中刷新出現(xiàn)404 index index.html index.htm; } #對應(yīng)上面的@router,主要原因是路由的路徑資源并不是一個真實(shí)的路徑,所以無法找到具體的文件 #因此需要rewrite到index.html中,然后交給路由在處理請求資源 location @router { rewrite ^.*$ /index.html last; } # /api :是代理到后端的前綴 location /api { #填寫直接的內(nèi)網(wǎng)IP地址 proxy_pass http://*.*.*.*:9001/; #proxy_pass http://&env; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header REMOTE-PORT $remote_port; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; rewrite ^/api/(.*) /$1 break; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } #nacos配置 location /nacos/ { rewrite ^//(.*)$ /$1 break; #填寫自己的內(nèi)網(wǎng)IP地址 proxy_pass http://*.*.*.*:8080/nacos; proxy_set_header Host $host; proxy_set_header User-Agent $http_user_agent; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header authorization $http_authorization; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
總結(jié)
以上為個人經(jīng)驗(yàn),希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
centos配置mutt和msmtp實(shí)現(xiàn)郵件發(fā)送
這篇文章主要為大家詳細(xì)介紹了centos配置mutt和msmtp實(shí)現(xiàn)郵件發(fā)送,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-11-11解決ssh遠(yuǎn)程登陸linux顯示-bash-4.1$的問題
下面小編就為大家?guī)硪黄鉀Qssh遠(yuǎn)程登陸linux顯示-bash-4.1$的問題。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-12-12增強(qiáng)Linux和Unix服務(wù)器安全性的方法詳解
今天小編就為大家分享一篇關(guān)于增強(qiáng)Linux和Unix服務(wù)器安全性的方法詳解,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2019-03-03centos7利用yum安裝lnmp的教程(linux+nginx+php7.1+mysql5.7)
lnmp相信不用多介紹了,大家應(yīng)該都知道,下面這篇文章主要給大家介紹了關(guān)于centos7利用yum安裝lnmp(linux+nginx+php7.1+mysql5.7)的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面來一起看看吧。2018-03-03