1.ubuntu安装nginx
sudo apt-get update
sudo apt-get install nginx
2.nginx反向代理配置
sudo vim /etc/nginx/sites-available/default
修改内容为:
# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
server {
listen 8888; # 监听80端口,可以根据需要修改端口号
server_name localhost; # 替换为你自己的域名或IP地址
location / {
root /var/www/html; # 设置Web根目录
index index.html; # 设置默认索引文件
}
}
upstream backend {
server localhost:8888; # 替换为你的后端服务器的地址或IP地址
}
server {
listen 8888;
server_name localhost; # 替换为你自己的域名或IP地址
location / {
proxy_pass http://backend; # 将请求代理到后端服务器
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
sudo systemctl restart nginx.service
3.web页面访问输入localohost:8888即可弹出自己写的界面