我的要求
鬼博客www.mydomain.com/blog
根目录中的index.html,contact.php,几个图像和js文件。 (即像www.mydomain.com/index.html,mydomain.com/contact.php等)
阅读本教程之后,我可以运行幽灵在www.mydomain.com/blog上。 但不幸的是,我无法访问根目录,即www.mydomain.com任何东西,因为它会引发404错误
在安装Ghost之前在/usr/share/nginx/www目录下的所有内容都可用。 现在,我用ls命令检查文件是否存在于文件夹/usr/share/nginx/www ,我可以在terminal上查看这些文件。
当我cd到/etc/nginx/sites-available/文件夹时,我可以看到2个文件ghost和default以及/etc/nginx/sites-enabled/我只能看到ghost文件。
当我将/etc/nginx/sites-available/的默认文件复制到/etc/nginx/sites-enabled/ ,Ghost Blog给出了一个404错误。
这里是默认文件内容服务器{listen 80 default_server; 听[::]:80 default_server ipv6only = on;
root /usr/share/nginx/html; index index.php index.html index.htm; # Make site accessible from http://localhost/ server_name localhost; location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; # Uncomment to enable naxsi on this location # include /etc/nginx/naxsi.rules } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } 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; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } 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; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} }
这里是鬼文件内容
server { listen 80; server_name SERVERIP/spider; location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $http_host; proxy_pass http://127.0.0.1:2368; } }
我经过一些强化Googlesearch之后find了解决scheme
现在,首先我从默认的Ghostconfiguration文件从站点可用文件夹复制到站点启用文件夹使用
cp /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default
在文件被复制后,我使用以下命令重新启动nginx service nginx restart
现在,当我刷新页面时,我看不到我的博客,但是根目录上的/usr/share/nginx/www文件夹都可用。 即该文件夹中的所有文件都可以在mydomain.com上访问
现在回到Ghost博客,我做了一个相同的备份,并将其从/etc/nginx/sites-enabled/default文件夹中删除。
相反,我在服务器对象内粘贴了以下代码。
location ^~ /blog { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-NginX-Proxy true; proxy_pass http://127.0.0.1:2368; proxy_redirect off; }
重新启动的nginx,它的工作!
来源https://allaboutghost.com/how-to-install-ghost-in-a-subdirectory/
我在下面的url中使用了解决scheme,它的工作。
server { listen 80; server_name localhost; location ^~ /blog { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-NginX-Proxy true; proxy_pass http://127.0.0.1:2368; proxy_redirect off; } }
https://www.ghostforbeginners.com/how-to-install-ghost-in-a-subdirectory/