溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

Linux下怎么配置Nginx反向代理

發(fā)布時(shí)間:2022-01-26 10:27:34 來(lái)源:億速云 閱讀:115 作者:小新 欄目:開(kāi)發(fā)技術(shù)

這篇文章主要介紹Linux下怎么配置Nginx反向代理,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!

反向代理功能是nginx的三大主要功能之一,反向代理服務(wù)器是一種代理服務(wù)器,用于管理從外部網(wǎng)絡(luò)到內(nèi)部網(wǎng)絡(luò)的連接或任何特定請(qǐng)求。它保護(hù)、路由和管理從外部網(wǎng)絡(luò)到內(nèi)部網(wǎng)絡(luò)、Web服務(wù)器或?qū)S镁W(wǎng)絡(luò)的流量。

Linux下怎么配置Nginx反向代理
img

1、升級(jí)系統(tǒng)、卸載Apache釋放80端口

Yum update -y
Yum remove httpd -y

2、安裝EPEL repo

rpm -Uvh http://mirror.ancl.hawaii.edu/linux/epel/6/i386/epel-release-6-8.noarch.rpm
EPEL repo下載地址:https://fedoraproject.org/wiki/EPEL

3、安裝Nginx,并設(shè)置

安裝Nginx

yum install nginx -y 調(diào)整Nginx配置

cd /etc/nginx/conf.d
mv default.conf default.conf.disabled

4、創(chuàng)建Nginx反代配置文件

cd /etc/nginx/conf.d
vi yourdomain.com

粘貼以下內(nèi)容:

server {
listen 80;
server_name yourdomain.com;
access_log off;
error_log off;
location / {
proxy_pass http://需要反代的服務(wù)器IP/;
proxy_redirect off;
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_max_temp_file_size 0;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
}

然后保存。

5、設(shè)置防火墻,允許80端口訪問(wèn)

iptables -I INPUT 5 -m state --state NEW -p tcp --dport 80 -j ACCEPT
service iptables save
service iptables restart

6、啟動(dòng)Nginx

service nginx start

以上是“Linux下怎么配置Nginx反向代理”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI