nginx配置

在/etc/nginx/conf.d目录下增加虚拟主机配置文件(*.conf):
server
    {
        listen 80;     #监听端口
        #server_name www.xxxx.cn;
        server_name xxx.xxx.xxx.xxx;    #监听域名
        index index.php index.html index.htm;  # 默认文件

        root /home/vagrant/workspace/www;  #根目录
 
        #error_page   404   /404.html;
   # php扩展支持
        location ~ .php$ {

       try_files $uri =404;
                include fastcgi.conf;
                fastcgi_pass 127.0.0.1:9000; # php-fpm 配置中监听地址相对应

        }
   # 路径改写,便于多项目同时工作
        location /test/ {
                try_files $uri $uri/ /test/public/index.php?$query_string;
        }
   # 状态配置
        location /nginx_status
        {
            stub_status on;
            access_log   off;
        }
   # 静态文件配置
        location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*.(js|css)?$
        {
            expires      12h;
        }

        location ~ /.
        {
            deny all;
        }
    }
重启nginx: service nginx restart

ps:配置完成,若不同,检查是否被防火墙过滤,避免防火墙过滤方法:

1 /etc/sysconfig/iptables 中添加-A INPUT -p tcp --dport 8080 -j ACCEPT

2 service  iptables restart

原文地址:https://www.cnblogs.com/--xiaoyao--/p/5421076.html