nginx - 将nginx 8080端口转发到80
问题描述
我有一个带有多个 nginx 实例的服务器
其中一个运行在 8080
server {
listen 8080;
server_name myip v2.example.com www.v2.example.com;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
proxy_pass http://v2.example.com:8080/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
但我想使用 example.com 进入站点,而不是 example.com:8080 问题是在端口 80 上运行了另一台服务器,我尝试使用代理通行证修复它,但它似乎不起作用
我该如何解决?
解决方案
用 重定向return
。您可以将以下内容放在一个文件中:
server {
listen 80;
listen [::]:80;
server_name v2.example.com www.v2.example.com;
return 301 http://$host$request_uri:8080;
}
server {
listen 8080;
server_name myip v2.example.com www.v2.example.com;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
推荐阅读
- amazon-web-services - AWS Glue - pySpark:将字符串列拆分为新的整数数组列
- batch-file - 字母范围的批处理文件递归,避免奇怪的短名称选择
- python - 如何配置 django 在 apache 上运行
- java - Kotlin - 调用getter时未加载HibernateProxy
- amazon-web-services - 如何使用无服务器部署没有身份源的 API Gateway 自定义授权方?
- tensorflow - 为什么 Tensorboard1.15 会为每个 global_step 创建一个单独的图?
- r - 使用 scale_color_manual 从一组特定变量中手动选择绘图线大小
- mysql - SQL:如果 *condition* 在另一行上,则更新一行
- c# - 将 BoxAnnotationViewModel 上的注释 X1 和 X2 设置在 CategoryDateTimeAxis 上的主要网格单元之间
- tkinter - Tkinter 列表框填充了从浏览按钮导入的未知文件的文件名?