【问题标题】:Nginx remove port number :8080 in the urlNginx 删除 url 中的端口号 :8080
【发布时间】:2015-10-21 21:04:34
【问题描述】:

我在 ubuntu VPS 上使用 apache 和 nginx。当我在那里托管网站时,Apache 具有端口 80 的优先级。

我有一个在端口 3000 上运行的小型 nodejs 应用程序。在 web 链接的目录中,我有一个 .htaccess 文件,该文件重定向到端口 8080(nginx 上的反向代理),但我仍然无法摆脱 :8080最后。

这是我的 .htaccess 文件

Options +FollowSymLinks
RewriteEngine on 
RewriteRule ^(.*)$ http://example.org:8080/$1 [R=301,L]

这是我的 nginx 配置

server {
  listen 8080;
  server_name example.org;
  port_in_redirect off;
  root /var/www/example.org/webapp;
  access_log /var/www/example.org/log/access.log;
  error_log /var/www/example.org/error.log;

  location / {
    proxy_pass http://example.org:3000;
    proxy_redirect http://example.org:8080/ http://example.org/;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
  }
}

我尝试过关闭/不关闭 port_in_redirect;代理重定向http://example.org:8080/http://example.org/

当我转到 example.org 时,它会重定向到 example.org:8080。有没有办法让 apache 和 nginx 共存而不会丢失我在 80 端口上的 apache 站点?

【问题讨论】:

    标签: node.js apache .htaccess nginx


    【解决方案1】:

    您可以将 Apache 用作反向代理,您可以将其直接定向到 nodejs 应用程序,除非您有某些原因也将它通过 nginx 传递。这将允许您在端口 80 上运行多个站点/应用程序。

    示例.htaccess / httpd.conf:

    RewriteEngine On
    RewriteRule ^$ http://127.0.0.1:3000/ [P,L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ http://127.0.0.1:3000/$1 [P,L]
    

    [P] 告诉 Apache 代理请求。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-02
      • 2014-07-18
      • 2011-07-04
      • 2020-02-20
      • 2016-10-04
      • 2015-07-19
      • 2015-08-17
      相关资源
      最近更新 更多