设置wordpress和gitlab,一次只能激活其中一个

设置wordpress和gitlab,一次只能激活其中一个

我正在尝试在 Ubuntu 14.04 机器上建立一个网站 (website.com)。

当存在“/etc/nginx/sites-available/wordpress”时,我可以在 website.com/gitlab 上运行 gitlab 服务器(按预期)

当存在“/etc/nginx/sites-available/gitlab”时,我可以在 website.com 上运行 wordpress 服务器(按预期)

当“wordpress”和“gitlab”都在“sites-available”中时,website.com/gitlab 可以访问,但 website.com 返回 403 禁止错误。

如何让 wordpress 和 gitlab 协同工作?

谢谢!

/etc/nginx/sites-available 上的配置文件

GitLab

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

## Normal HTTP host
server {
  listen 0.0.0.0:80;
  listen [::]:80;
  server_name localhost ztomer.ax.lt; ## Replace this with something like gitlab.example.com
  server_tokens off; ## Don't show the nginx version number, a security best practice
  root /home/git/gitlab/public;

  client_max_body_size 20m;

  ## See app/controllers/application_controller.rb for headers set

  ## Individual nginx logs for this GitLab vhost
  access_log  /var/log/nginx/gitlab_access.log;
  error_log   /var/log/nginx/gitlab_error.log;

  location ~* /gitlab {
    alias /home/git/gitlab/public;
    try_files $uri $uri/index.html $uri.html @gitlab;
  }

  location @gitlab {
    proxy_read_timeout      300;
    proxy_connect_timeout   300;
    proxy_redirect          off;

    proxy_set_header    Host                $http_host;
    proxy_set_header    X-Real-IP           $remote_addr;
    proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;
    proxy_set_header    X-Forwarded-Proto   $scheme;
    proxy_set_header    X-Frame-Options     SAMEORIGIN;

    proxy_pass http://gitlab;
  }

  location ~ ^/(assets)/ {
    root /home/git/gitlab/public;
    gzip_static on; # to serve pre-gzipped version
    expires max;
    add_header Cache-Control public;
  }

  error_page 502 /502.html;
}

WordPress的

server {
    listen 80;
    listen [::]:80 ipv6only=on;

    root /var/www/html;
    index index.php index.html index.htm;

    # Make site accessible from http://localhost/
    server_name localhost ztomer.ax.lt;

    location = / {
        try_files /nonexistent /index.php?q=$uri&$args;
    }

# magically link wordpress here
    location / {        
        try_files $uri $uri/ $uri/index.html /index.php?q=$uri&$args;
    }
    error_page 404 /404.html;

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;

        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

}

}

答案1

您需要更新root配置中的指令,假设您的 WordPress 位于 和 下/var/www/html而不是/home/git/gitlab/public

答案2

成功!! 纠正步骤:

  1. 使用单个站点文件
  2. 为每个位置块添加了明确的根指令
  3. 解析的顺序很重要,我把 location / {} 块放在第一位
  4. 向位置/{} 块添加了索引指令。

谢谢你们的帮助!

工作配置文件:

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

## Normal HTTP host
server {
  listen 0.0.0.0:80;
  listen [::]:80;
  server_name localhost ztomer.ax.lt; ## Replace this with something like gitlab.example.com
  server_tokens off; ## Don't show the nginx version number, a security best practice
  # root /home/git/gitlab/public;

  ## Increase this if you want to upload large attachments
  ## Or if you want to accept large git objects over http
  client_max_body_size 1024m;

  ## See app/controllers/application_controller.rb for headers set

  ## Individual nginx logs for this GitLab vhost
  access_log  /var/log/nginx/gitlab_access.log;
  error_log   /var/log/nginx/gitlab_error.log;

 # magically link wordpress here
   location / {
       root /var/www/html;
       index index.php;
       try_files $uri $uri/ $uri/index.html /index.php?q=$uri&$args;
   }
   error_page 404 /404.html;

   error_page 500 502 503 504 /50x.html;
   location = /50x.html {
        root /usr/share/nginx/html;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
   location ~ \.php$ {
       root /var/www/html;
       try_files $uri =404;
       fastcgi_split_path_info ^(.+\.php)(/.+)$;

       fastcgi_pass unix:/var/run/php5-fpm.sock;
       fastcgi_index index.php;
       include fastcgi_params;
   }

  location ~* /gitlab {
    root /home/git/gitlab/public;
    ## Serve static files from defined root folder.
    ## @gitlab is a named location for the upstream fallback, see below.
    # alias /home/git/gitlab/public;
    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 passes the request to the upsteam (gitlab unicorn).
  location @gitlab {
    root /home/git/gitlab/public;
    ## If you use HTTPS make sure you disable gzip compression
    ## to be safe against BREACH attack.
    # gzip off;

    ## https://github.com/gitlabhq/gitlabhq/issues/694
    ## Some requests take more than 30 seconds.
    proxy_read_timeout      300;
    proxy_connect_timeout   300;
    proxy_redirect          off;

    proxy_set_header    Host                $http_host;
    proxy_set_header    X-Real-IP           $remote_addr;
    proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;
    proxy_set_header    X-Forwarded-Proto   $scheme;
    proxy_set_header    X-Frame-Options     SAMEORIGIN;

    proxy_pass http://gitlab;
  }

  ## Enable gzip compression as per rails guide:
  ## http://guides.rubyonrails.org/asset_pipeline.html#gzip-compression
  ## WARNING: If you are using relative urls remove the block below
  ## See config/application.rb under "Relative url support" for the list of
  ## other files that need to be changed for relative url support
  location ~ ^/(assets)/ {
    root /home/git/gitlab/public;
    gzip_static on; # to serve pre-gzipped version
    expires max;
    add_header Cache-Control public;
  }

  # error_page 502 /502.html;

}

相关内容