Nginx:两个虚拟主机

时间:2016-08-12 15:23:21

标签: nginx

一个是博客,另一个是网络应用,使用两个虚拟主机,两个二级域

blog.example.com

webapp.example.com

vitual.conf文件在/etc/nginx/conf.d下,在nginx配置文件中包含这个,这里是virtual.conf

 ######################for blog##############################
    server {
            listen  80;
            server_name  blog.example.cn;
            access_log  /www/access_blog  main;
            location / {
                root   /www/blog;
                index  index.php index.html index.htm;
            }
            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$ {
             fastcgi_pass   127.0.0.1:9000;
             fastcgi_index   index.php;
             fastcgi_param  SCRIPT_FILENAME   /www/blog/$fastcgi_script_name;
             include        fastcgi_params;
          }
            location ~ /.ht {
                deny  all;
            }
    }
    #######################for web app#######################
    server {
            listen  80;
            server_name webapp.example.com; 
            access_log  /www/access_webapp  main;
            location / {
                root   /www/webapp;
                index  index.php index.html index.htm;
            }
            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$ {
             fastcgi_pass   127.0.0.1:9000;
             fastcgi_index   index.php;
             fastcgi_param  SCRIPT_FILENAME   /www/oclass/$fastcgi_script_name;
             include        fastcgi_params;
          }
            location ~ /.ht {
                deny  all;
            }
    }

网页应用可以正常投放,但输入https://blog.example.com的地址后,请务必转到https://blog.example.com:8888

似乎nginx将请求转发到端口8888,所以我改变了博客的服务器来监听端口8888,

#######################for web app#######################
server {
        listen  8888;
然后它工作,nginx可以正常服务博客,(顺便说一下方向/ www的权限模式是755)但是如何解决这个问题,对于博客和网络应用服务器都可以听80?

0 个答案:

没有答案