Nginx 和 Jekyll:在子域中服务
Nginx and Jekyll: serving in a subdomain
我目前正在配置 Jekyll 和 nginx 以在 VPS 上协同工作。
本质上,我设置了所有内容和一个从本地机器到 VPS 的 git 挂钩。
这是我的 nginx 配置文件:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www;
index index.php index.html index.htm;
server_name server_ip;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
server {
listen 80;
server_name server_ip/blog;
location / {
root /var/www/blog;
index index.html index.htm;
}
}
理想情况下,我想要在 blog.domain.example
或 blog.server_ip
提供 /var/www/blog
中的内容。
但是,当jekyll build
运行时,URL都出错了。我可以在 server_ip/blog
处看到 index.html
,但 URL 中的 /blog/
位未复制到 Jekyll 页面上的链接中。
例如,一个post应该住在server_ip/blog/2015/04/07/title
,但我得到的URL是server_ip/2015/04/07/title
。 CSS 文件和图像也是如此。
非常感谢您的帮助。
你必须设置baseurl: "/blog"
和 link 这样的帖子 <a href="{{site.baseurl}}{{post.url}}>...
。
并且通常使用 {{site.baseurl}}
来构建任何 url。
我目前正在配置 Jekyll 和 nginx 以在 VPS 上协同工作。 本质上,我设置了所有内容和一个从本地机器到 VPS 的 git 挂钩。
这是我的 nginx 配置文件:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www;
index index.php index.html index.htm;
server_name server_ip;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
server {
listen 80;
server_name server_ip/blog;
location / {
root /var/www/blog;
index index.html index.htm;
}
}
理想情况下,我想要在 blog.domain.example
或 blog.server_ip
提供 /var/www/blog
中的内容。
但是,当jekyll build
运行时,URL都出错了。我可以在 server_ip/blog
处看到 index.html
,但 URL 中的 /blog/
位未复制到 Jekyll 页面上的链接中。
例如,一个post应该住在server_ip/blog/2015/04/07/title
,但我得到的URL是server_ip/2015/04/07/title
。 CSS 文件和图像也是如此。
非常感谢您的帮助。
你必须设置baseurl: "/blog"
和 link 这样的帖子 <a href="{{site.baseurl}}{{post.url}}>...
。
并且通常使用 {{site.baseurl}}
来构建任何 url。