CentOS系統(tǒng)rpm安裝Nginx和配置
CentOS rpm安裝Nginx和配置
官方下載地址: http://nginx.org/en/download.html
介紹
Nginx(“engine x”)是一款由俄羅斯的程序設(shè)計(jì)師Igor Sysoev所開發(fā)高性能的 Web和 反向代理 服務(wù)器,也是一個(gè) IMAP/POP3/SMTP 代理服務(wù)器。
rpm包安裝
#安裝nginx,rpm安裝
#rpm安裝nginx包
rpm -Uvh --force --nodeps nginx-1.16.1-1.el7.ngx.x86_64.rpm
#查看啟動(dòng)狀態(tài)
systemctl status nginx
顯示如下:
● nginx.service - nginx - high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: active (running) since 五 2021-11-26 11:12:41 CST; 5 days ago
Docs: http://nginx.org/en/docs/
Process: 1379 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
Main PID: 1543 (nginx)
Tasks: 5
CGroup: /system.slice/nginx.service
├─1543 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
├─1544 nginx: worker process
├─1546 nginx: worker process
├─1547 nginx: worker process
└─1548 nginx: worker process
11月 26 11:12:41 liang systemd[1]: Starting nginx - high performance web server...
11月 26 11:12:41 liang systemd[1]: Started nginx - high performance web server.
#啟動(dòng)
systemctl start nginx
#重啟
systemctl restart nginx
#開機(jī)自啟動(dòng)服務(wù)
systemctl enable nginx
#查看開機(jī)啟動(dòng)狀態(tài) enabled:開啟, disabled:關(guān)閉
systemctl is-enabled nginx
安裝完后在 修改 /etc/nginx/conf.d/default.conf 配置文件,參考內(nèi)容如下:
vim /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location /ui {
alias /data/dist;
index index.html index.htm;
}
location /file/ {
root /home/data/;
index index.html index.htm;
}
# websocket配置wss
location /liangws/ {
proxy_pass http://192.168.0.19:8080/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Remote_addr $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 600s;
}
location ~ /gat {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:18080 ;
}
#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 /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
注意:靜態(tài)文件下載,需要依賴nginx,我們需要將這些文件放到 nginx配置文件中的 /home/data/aaa 對(duì)應(yīng)的目錄下。
啟動(dòng)服務(wù)配置
cat /usr/lib/systemd/system/nginx.service
[Unit] Description=nginx - high performance web server Documentation=http://nginx.org/en/docs/ After=network-online.target remote-fs.target nss-lookup.target Wants=network-online.target [Service] Type=forking PIDFile=/var/run/nginx.pid ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s TERM $MAINPID [Install] WantedBy=multi-user.target
到此這篇關(guān)于CentOS系統(tǒng)rpm安裝Nginx和配置的文章就介紹到這了,更多相關(guān)CentOS rpm安裝Nginx內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Nginx服務(wù)器中設(shè)置禁止訪問(wèn)文件或目錄的方法
這篇文章主要介紹了Nginx服務(wù)器中設(shè)置禁止訪問(wèn)文件或目錄的方法,對(duì)于協(xié)同遠(yuǎn)程管理服務(wù)器的情況來(lái)講很有實(shí)用性,需要的朋友可以參考下2015-07-07
Nginx負(fù)載均衡之upstream模塊簡(jiǎn)介與使用詳解
nginx有一個(gè)最大的功能就是可以實(shí)現(xiàn)服務(wù)器的負(fù)載均衡,下面這篇文章主要給大家介紹了關(guān)于Nginx負(fù)載均衡之upstream模塊簡(jiǎn)介與使用的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-09-09
nginx配置proxy_pass后返回404問(wèn)題以及Nginx host相關(guān)變量的說(shuō)明
這篇文章主要介紹了nginx配置proxy_pass后返回404問(wèn)題以及Nginx host相關(guān)變量的說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-01-01
使用Nginx搭建圖片服務(wù)器(windows環(huán)境下)
這篇文章主要介紹了使用Nginx搭建圖片服務(wù)器(windows環(huán)境下),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-06-06
nginx中狀態(tài)統(tǒng)計(jì)的實(shí)現(xiàn)
本文主要介紹了nginx中狀態(tài)統(tǒng)計(jì)的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-04-04
解決nginx訪問(wèn)頁(yè)面中文亂碼的問(wèn)題
這篇文章主要為大家介紹了nginx訪問(wèn)頁(yè)面中文亂碼解決方案,文中有相關(guān)的代碼示例供大家參考,有需要的朋友可以借鑒參考下,希望能夠有所幫助2023-09-09
nginx配置多個(gè)前端項(xiàng)目實(shí)現(xiàn)步驟
本文主要介紹了nginx配置多個(gè)前端項(xiàng)目實(shí)現(xiàn)步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-03-03
nginx鏡像構(gòu)建的知識(shí)點(diǎn)及方法步驟詳解
這篇文章主要為大家介紹了nginx鏡像構(gòu)建的知識(shí)點(diǎn)詳解,<BR>有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-08-08

