erreur de configuration nginx
为情所困
为情所困 2017-06-06 09:54:31
0
2
1048

configuration nginx

# user  nobody;
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;

    # 开启gzip
    gzip on;
    # 启用gzip压缩的最小文件,小于设置值的文件将不会压缩
    gzip_min_length 1k;
    # gzip 压缩级别,1-10,数字越大压缩的越好,也越占用CPU时间,后面会有详细说明
    gzip_comp_level 2;
    # 进行压缩的文件类型。javascript有多种形式。其中的值可以在 mime.types 文件中找到。
    gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
    # 是否在http header中添加Vary: Accept-Encoding,建议开启
    gzip_vary on;
    # 禁用IE 6 gzip
    gzip_disable "MSIE [1-6]\.";

    #配置nginx缓存
    proxy_cache_path /etc/nginx/cache levels=1:2 keys_zone=cache_one:500m inactive=10d max_size=10g;
    proxy_temp_path /etc/nginx/cache/temp;

    upstream service {
        ip_hash;
        server 127.0.0.1:13333 max_fails=2 fail_timeout=5s;
        server 127.0.0.1:13334 max_fails=2 fail_timeout=5s;
    }

    server {
        listen       80;
        server_name  xxxxx.com;

        listen       443 ssl;
        underscores_in_headers on;
        ignore_invalid_headers off;

        ssl_certificate      cert/214001950380329.pem;
        ssl_certificate_key  cert/214001950380329.key;

        ssl_session_cache shared:SSL:10m;
        ssl_session_timeout 10m;

        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;

        #charset utf-8;

        #access_log  logs/host.access.log  main;

        #网站首页
        location / {
            root   /data/www/;     #html;
            index  index.html index.htm;
        }

        #后台工程配置
        location ^~/admin/ {
            alias   /data/backend/www/;
            index  index.html;
        }
        location /api/ {
            proxy_pass http://localhost:3000/api;
        }

        location /service {
            proxy_set_header X-Real-IP  $http_x_forwarded_for;
            proxy_set_header Host $host;
            proxy_pass http://service;
        }

        location ~ .*\.(js|css|gif|jpg|jpeg|png|webp|bmp|swf|flv)$ {
            root /data/www; 
            #向upstream服务器同时发送http头,头信息中包括Host:主机、X-Real-IP:客户端真实IP地址
            proxy_set_header   Host $host:$server_port;
            proxy_set_header   X-Real-IP   $remote_addr;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for; 
            proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
            # proxy_pass http://127.0.0.1;
            # proxy_redirect off;
            #上面定义的cache_one缓存区被用于这个位置。 Nginx会在这里检查传递给后端有效的条目。
            proxy_cache       cache_one;
            proxy_cache_valid 200 304 12h;
            proxy_cache_valid any 10m;
            proxy_cache_key   $host$uri$is_args$args;
            add_header  Nginx-Cache "$upstream_cache_status";  
            expires max;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

    }

    include servers/*;
}

erreur.log

2017/06/02 15:50:12 [error] 26536#26536: *3768 open() "/data/www/admin" failed (2: No such file or directory), client: xxxxxxxxx, server: xxxxx.com, request: "GET /admin HTTP/1.1", host: "xxxxx.com"

Le répertoire de la page d'accueil du site Web se trouve à /data/www
La page d'accueil de l'administrateur est à /data/backend/www/

Quelle devrait être la bonne combinaison ?

为情所困
为情所困

répondre à tous(2)
世界只因有你

Étant donné que le chemin que vous avez configuré correspond à /admin/ et que l'URL commence par /admin/, /data/www/admin est demandé

Lorsque vous visitez xxxxx.com/admin, cela équivaut au premier correspondant

   #网站首页
    location / {
        root   /data/www/;     #html;
        index  index.html index.htm;
    }

Visitez xxxxx.com/admin/ pour trouver le match

    #后台工程配置
    location ^~/admin/ {
        alias   /data/backend/www/;
        index  index.html;
    }

De plus, vous pouvez également le changer en deux serveurs pour isoler fondamentalement la page d'accueil du site et le côté gestion du site, ce qui facilitera également l'ajout de noms de domaine ultérieurement

PHPzhong

Sous quel utilisateur votre nginx fonctionne-t-il ? Quelles sont les autorisations du répertoire /data/www/admin ? Vérifiez-le

 ?
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!