Nginx 反向代理配置

centos7安裝nginx

sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

安裝Nginx

sudo yum install -y nginx

查找編輯Nginx配置文件

whereis nginx
cd /etc/nginx
vi nginx.conf

修改

server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}

爲如下:

server {
listen 80;
# listen [::]:80 default_server;
server_name xxx.xxx.xx.xx; # 反向代理服務器IP
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
proxy_pass http://xxx.xxx.xx.xx:3000; # web服務器IP、端口
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}

啓動Nginx

sudo systemctl start nginx.service

停止Nginx

sudo systemctl stoN nginx.service

卸載Nginx

sudo yum remove -y nginx

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章