访问代码 304:从主机访问 vmware 中的 nginx

访问代码 304:从主机访问 vmware 中的 nginx

我已经成功安装了使用 nginx 的 gitlab(感谢这个线程:gitlab 安装:使用 localhost)。我可以在 localhost 中运行该软件(http://localhost 将带我进入 gitlab 首页)。所有这些都在 vmware 中。

我尝试将主机 666 端口映射到 vmware ngnix 80 端口。因此,访问 http://localhost:666 应该会显示 gitlab 首页。

问题是:我只得到“欢迎使用 nginx!”页面。

我的访问日志如下所示:

10.1.17.74 - - [25/Mar/2013:00:24:59 -0700] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22"

-

ls -l /etc/nginx/sites-*

生产

/etc/nginx/sites-available:
total 8
-rw-r--r-- 1 root root 2496 2011-02-25 19:20 default
-rw-r--r-- 1 root root 1198 2013-03-24 09:12 gitlab

/etc/nginx/sites-enabled:
total 0
lrwxrwxrwx 1 root root 34 2013-03-24 03:59 default -> /etc/nginx/sites-available/default
lrwxrwxrwx 1 root root 33 2013-03-24 04:00 gitlab -> /etc/nginx/sites-available/gitlab

内容/etc/nginx/sites-available/gitlab

# GITLAB
# Maintainer: @randx
# App Version: 5.0

upstream gitlab {
  server unix:/home/git/gitlab/tmp/sockets/gitlab.socket;
}

server {
  listen 127.0.0.1:80 default_server;         # e.g., listen 192.168.1.1:80;
  server_name localhost;     # e.g., server_name source.example.com;
  root /home/git/gitlab/public;

  # individual nginx logs for this gitlab vhost
  access_log  /var/log/nginx/gitlab_access.log;
  error_log   /var/log/nginx/gitlab_error.log;

  location / {
    # serve static files from defined root folder;.
    # @gitlab is a named location for the upstream fallback, see below
    try_files $uri $uri/index.html $uri.html @gitlab;
  }

  # if a file, which is not found in the root folder is requested,
  # then the proxy pass the request to the upsteam (gitlab unicorn)
  location @gitlab {
    proxy_read_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
    proxy_connect_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
    proxy_redirect     off;

    proxy_set_header   X-Forwarded-Proto $scheme;
    proxy_set_header   Host              $http_host;
    proxy_set_header   X-Real-IP         $remote_addr;

    proxy_pass http://gitlab;
  }
}

答案1

由于默认配置,可能会出现“欢迎使用 nginx”消息:

/etc/nginx/站点可用/默认

我假设 nginx 正在这里监听,并将您指向 nginx 欢迎页面。

移动/删除此文件应该可以解决问题。当然,如果我们能确切地看到该文件中的内容以更好地解释正在发生的事情,那就太好了。

答案2

感谢 Ladadadada 和 Drew Khoury 为我指明了正确的追求方向……

如果你在 vmware 中搭建了 gitlab 服务器,然后你想从主机环境访问它,同时,你又想通过虚拟机访问它,那么你需要进行如下/etc/nginx/sites-available/default设置:/etc/nginx/sites-available/gitlab

/etc/nginx/站点可用/默认

server {
  listen 127.0.0.1:80 default_server;         # e.g., listen 192.168.1.1:80;
  server_name localhost;     # e.g., server_name source.example.com;
  root /home/git/gitlab/public;

  # individual nginx logs for this gitlab vhost
  access_log  /var/log/nginx/gitlab_access.log;
  error_log   /var/log/nginx/gitlab_error.log;

  location / {
    # serve static files from defined root folder;.
    # @gitlab is a named location for the upstream fallback, see below
    try_files $uri $uri/index.html $uri.html @gitlab;
  }

  # if a file, which is not found in the root folder is requested,
  # then the proxy pass the request to the upsteam (gitlab unicorn)
  location @gitlab {
    proxy_read_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
    proxy_connect_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
    proxy_redirect     off;

    proxy_set_header   X-Forwarded-Proto $scheme;
    proxy_set_header   Host              $http_host;
    proxy_set_header   X-Real-IP         $remote_addr;

    proxy_pass http://gitlab;
  }
}

/etc/nginx/sites-available/gitlab

# GITLAB
# Maintainer: @randx
# App Version: 5.0

upstream gitlab {
  server unix:/home/git/gitlab/tmp/sockets/gitlab.socket;
}

server {
  listen 192.168.21.136:80 default_server;         # e.g., listen 192.168.1.1:80;
  server_name localhost;     # e.g., server_name source.example.com;
  root /home/git/gitlab/public;

  # individual nginx logs for this gitlab vhost
  access_log  /var/log/nginx/gitlab_access.log;
  error_log   /var/log/nginx/gitlab_error.log;

  location / {
    # serve static files from defined root folder;.
    # @gitlab is a named location for the upstream fallback, see below
    try_files $uri $uri/index.html $uri.html @gitlab;
  }

  # if a file, which is not found in the root folder is requested,
  # then the proxy pass the request to the upsteam (gitlab unicorn)
  location @gitlab {
    proxy_read_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
    proxy_connect_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
    proxy_redirect     off;

    proxy_set_header   X-Forwarded-Proto $scheme;
    proxy_set_header   Host              $http_host;
    proxy_set_header   X-Real-IP         $remote_addr;

    proxy_pass http://gitlab;
  }
}

请更改192.168.21.136为您的 vmware IP 地址。在主机中,您有“虚拟网络编辑器”菜单,您可以在其中将 vmware IP 地址映射到特定端口。

相关内容