【Nginx】nginx虚拟机设置

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

假设我们目前有一个已经设置好的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;
}

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值