nginx虚拟机设置

babyzn 8年前

来自: http://blog.csdn.net/diandianxiyu_geek/article/details/48444659


一般情况下,我们的一台机器都不会仅仅部署一个项目,那么这个时候需要我们设置虚拟机来映射多个地址的解析。

假设我们目前有一个已经设置好的nginx服务器,通过php-fpm提供服务。

找到配置文件地址

有的时候我们不知道配置文件在哪里,而不同版本的Linux发行版的差距又很大,那么这个时候,就需要去找配置文件的位置

[root@iZ28405a6nlZ ~]# whereis nginx  nginx: /usr/sbin/nginx /etc/nginx /usr/share/nginx

这样就找到了配置文件的位置/etc/nginx

设置配置文件

进去配置文件夹,发现里面有个conf.d的文件夹,这里面的配置文件,每次重启都会被加载进去,在这个里面创建你的域名.conf的文件,例如www.localhost.com.conf

下面是我写的例子,每个服务器的配置都会差别,不要随便拿过来用

server {      listen       80;      server_name www.xxx.com;      index index.html index.htm index.php;      root  /usr/share/nginx/html/xxx;        location / {            try_files $uri $uri/ /index.php?$args;            if (!-e $request_filename){            rewrite ^/(.*) /index.php last;            }            root   /usr/share/nginx/html/markweb;            index  index.php  index.html  index.htm;        }           location ~ \.php$ {          root           /usr/share/nginx/html/xxx;          include  fastcgi_params;          fastcgi_pass   127.0.0.1:9000;          fastcgi_index  index.php;          fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html/markweb$fastcgi_script_name;         # include fastcgi_params;      }        log_format www.xxx.com '$remote_addr - $remote_user [$time_local] $request'      '$status $body_bytes_sent $http_referer '      '$http_user_agent $http_x_forwarded_for';      access_log  /var/log/www.xxx.com.log www.xxx.com;  }

重启之后设置对应的域名解析就可以咯~