правила перезаписи не работают с nginx

location / {
rewrite ^/test$ /test.php last;
}

, я добавил это в /usr/local/nginx/conf/vhost.d/example.com.rewrite

также протестировал

rewrite ^/test$ /test.php last;

Но переход на https://www.example.com/test просто вернет ошибку 404

После добавления правила я перестроил nginx, а затем перезапустил

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
Reloading nginx:                                           [  OK  ]

что я делаю не так?

Я Я использую CentOS 6.9

/usr/local/nginx/conf/vhost.ssl.d/example.com.conf

#:nginx:Nginx+ PHP-FPM Default  Stand Alone:2.0:
server {
    listen    144.217.68.82:443 ssl http2 ;
    server_name  example.com www.example.com;
    root /home/ndnmdev/public_html;
    index index.php index.php5 index.php4 index.php3 index.perl index.pl  index.cgi  index.phtml index.shtml index.xhtml index.html index.htm index.wml Default.html Default.htm default.html de$

    ssl on;
    ssl_certificate /usr/local/nginx/conf/ssl.cert.d/example.com_cert;
    ssl_certificate_key /usr/local/nginx/conf/ssl.key.d/example.com_key;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
    ssl_prefer_server_ciphers on;
    ssl_ciphers "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AE$
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout  5m;

    #.............. Cpnginx OCSP stapling protection for security start ....................
    ssl_stapling on;
    ssl_stapling_verify on;
    ssl_trusted_certificate /usr/local/nginx/conf/ssl.ca.d/example.com_ca-bundle;
    resolver 127.0.0.1 8.8.8.8 4.2.2.1 8.8.4.4 4.2.2.2  valid=300s;
    resolver_timeout 5s;
    #.............. Cpnginx OCSP stapling protection for security end....................

    location = /favicon.ico {
        log_not_found off;
    }


    access_log /usr/local/apache/domlogs/example.com-bytes_log bytes_log buffer=32k flush=5m;
    access_log /usr/local/apache/domlogs/example.com-ssl_log combined buffer=32k flush=5m;

    referer_hash_bucket_size 512;
    # Run Staic  file directly from nginx
    location ~* ^.+.(jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|iso|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|mp3|ogv|ogg|flv|swf|mpeg|mpg|mpeg4|mp4|avi|wmv|js|css|3gp|sis|sisx|nth|svg)$ {
        expires 30d;
        add_header Pragma public;
        add_header Cache-Control "public, must-revalidate, proxy-revalidate";
    }
    keepalive_requests 100;
    keepalive_timeout 60s;
    autoindex on;
    # Disable direct access to .ht files and folders
    location ~ /\.ht {
          deny all;
    }
    # Access all ****** services
    location ~* ^/(******|webmail|***|bandwidth|img-sys|java-sys|mailman/archives|pipermail|sys_******|cgi-sys|mailman) {
        proxy_pass   http://144.217.68.82:9080;
        proxy_set_header   Host   $host;
        proxy_set_header   X-Real-IP  $remote_addr;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
    }







    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/opt/******/ea-php70/root/usr/var/run/php-fpm/ndnmdev.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include /usr/local/nginx/conf/fastcgi_params;

        }

    # Allow Let's Encrypt client authentication - letsencrypt.org RFC 5785
    location ~ /.well-known { allow all; }

    location / {
        include /usr/local/nginx/conf/vhost.ssl.d/example.com.rewrite;
        client_max_body_size    2000m;
        client_body_buffer_size 512k;
        try_files $uri $uri/ /index.php?$args;


    }
    # include /usr/local/nginx/conf/vhost.ssl.d/example.com.include;

}

server {
    listen    144.217.68.82:443 ssl http2 ;
    server_name ******.example.com ***.example.com webmail.example.com webdisk.example.com cpcalendars.example.com cpcontacts.ni-dieu-ni-$
    ssl on;
    ssl_certificate /usr/local/nginx/conf/ssl.cert.d/example.com_cert;
    ssl_certificate_key /usr/local/nginx/conf/ssl.key.d/example.com_key;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout  5m;
    access_log off;
    location / {
            location ~ /.well-known{
                root /home/ndnmdev/public_html;
            }
        proxy_pass   https://127.0.0.1:9443;
        proxy_set_header   Host   $host;
        proxy_set_header   X-Real-IP  $remote_addr;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}
0
задан 5 April 2018 в 00:20
1 ответ

Я подозреваю, что регулярное выражение работает, но не дает ожидаемого результата, это зависит от платформы. Если вы напишете

rewrite ^/test$ http://www.example.com/test.php last;

, это сработает. Пожалуйста, проверьте свой доступ и журнал ошибок, чтобы увидеть, куда вы указали своим синтаксисом. Пожалуйста, не добавляйте второй блок.

0
ответ дан 5 December 2019 в 06:20

Теги

Похожие вопросы