美文网首页
Nginx配置启动踩坑之路

Nginx配置启动踩坑之路

作者: 江江简书 | 来源:发表于2020-11-16 19:08 被阅读0次

    Nginx作为负载均衡服务器优选,那能不研究一下,上来就是踩到几个坑

    nginx多站点配置不生效

    • nginx.confi配置
    user comp comp; # 设置nginx启动的用户
    #user nginx nginx;
    worker_processes  1;
    error_log  logs/error.log;
    #error_log  logs/error.log  notice;
    #error_log  logs/error.log  info;
    #pid        logs/nginx.pid;
    events {
        worker_connections  1024;
    }
    http {
        include       mime.types;
        default_type  application/octet-stream;
        #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
        #                  '$status $body_bytes_sent "$http_referer" '
        #                  '"$http_user_agent" "$http_x_forwarded_for"';
        #access_log  logs/access.log  main;
        sendfile        on;
        #tcp_nopush     on;
        #keepalive_timeout  0;
        keepalive_timeout  65;
        include /usr/local/nginx/vhost/*.conf;# 站点主要在这个位置其余参数默认即可
    }
    
    • 站点conf配置
    server {
        listen 80;
        server_name 127.0.0.1;
        location / {
            root home / comp / freetimego /public;
        index index . php index . html index . htm;
        if (!-e $request_filename){
                 rewrite ^ (.*)$ /index . php / $1;
        }
      }
        location ~ ^(.+\.php)(.*)${
        root / home / comp / freetimego /public; # 我的最终报错是在这里
        fastcgi_split_path_info ^ (.+\.php)(.*)$;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index index . php;
        include fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME    
        $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_script_name;
      }
     }
    

    我的报错是File not found.

    • 通过在nginx 的log日志中发现权限不对,因此把nginx和php-fpm都设置成同一个,在nginx.conf和php-fpm.conf(这里有可能是分离的就像vhost那样),设置成这个后还存在错误。

    • 最后发现是vhost中的路径少了/参数

    • 参考文章

    https://blog.csdn.net/zhezhebie/article/details/73497150?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-3.edu_weight&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-3.edu_weight

    相关文章

      网友评论

          本文标题:Nginx配置启动踩坑之路

          本文链接:https://www.haomeiwen.com/subject/yypzbktx.html