在 Nginx 上设置子域
我使用 Nginx 在我的服务器上安装了 2 个应用程序:
- Rails 应用程序
- WordPress 博客
我希望可以通过以下方式访问 Rails 应用程序:staging.mydomain.com 并且可以通过以下方式访问 WordPress 博客: blog.mydomain.com
该网站工作正常,但当我尝试访问该博客时,我会看到“欢迎来到 nginx”屏幕。
这是我的 nginx 配置:
server {
listen 80;
server_name staging.mydomain.com;
rails_env staging;
access_log /srv/www/staging/www/logs/access.log;
error_log /srv/www/staging/www/logs/error.log;
location / {
root /srv/www/staging/www/current/trunk/web/public;
passenger_enabled on;
}
}
server {
listen 80;
server_name blog.mydomain.com;
try_files $uri $uri/ /index.php;
access_log /srv/www/blog.mydomain.com/logs/access.log;
error_log /srv/www/blog.mydomain.com/logs/error.log;
location ~ \.php$ {
root /srv/www/blog.mydomain.com;
include fastcgi_params;
fastcgi_pass localhost:53217;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
有想过这里出了什么问题吗?
I have 2 application installed on my server using Nginx:
- Rails application
- wordpress blog
I want that the rails app will be accessible through: staging.mydomain.com
and that the wordpress blog will be accessible through: blog.mydomain.com
the site works fine but when i try to access the blog i get "welcome to nginx" screen.
here is my nginx config:
server {
listen 80;
server_name staging.mydomain.com;
rails_env staging;
access_log /srv/www/staging/www/logs/access.log;
error_log /srv/www/staging/www/logs/error.log;
location / {
root /srv/www/staging/www/current/trunk/web/public;
passenger_enabled on;
}
}
server {
listen 80;
server_name blog.mydomain.com;
try_files $uri $uri/ /index.php;
access_log /srv/www/blog.mydomain.com/logs/access.log;
error_log /srv/www/blog.mydomain.com/logs/error.log;
location ~ \.php$ {
root /srv/www/blog.mydomain.com;
include fastcgi_params;
fastcgi_pass localhost:53217;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
any thought about what is wrong here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能想要将博客的
server_name
更改为blog.mydomain
:我猜您正在尝试访问 blog.mydomain,但忘记更改
server_name< /代码>。
尝试使用
index
指令而不是try_files
:此外,
root
指令需要指向包含 index.php 文件的文件夹:You might want to change
server_name
for your blog toblog.mydomain
:I'm guessing you are trying to access blog.mydomain, but forgot to change
server_name
.Try to use the
index
directive instead oftry_files
:Also the
root
directive needs to point to the folder containing your index.php file:将指令
root /srv/www/blog.mydomain.com;
从location {}
移动到server {}
块。并添加根目录的位置。
Move directive
root /srv/www/blog.mydomain.com;
fromlocation {}
toserver {}
block.And add location for root directory.
固定的!使用这篇文章:http://wiki.nginx.org/Wordpress
fixed! used this post: http://wiki.nginx.org/Wordpress