私はNGINXウェブサーバー上にあり、URLから.php
という拡張子を削除したいと思います。いくつかの類似事例の指示に従うことを試みたが、何も私のconfで動作するように思われなかった場合NGINXで.php拡張子を削除してください
server {
server_name www.mywebsite.com mywebsite.com;
return 301 https://mywebsite.com$request_uri;
}
server {
listen 443 ssl;
server_name www.mywebsite.com;
return 301 https://mywebsite.com$request_uri;
ssl_certificate /etc/letsencrypt/live/mywebsite.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mywebsite.com/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
}
server {
listen 443 ssl;
root /opt/http/nginx/sites/mywebsite/www;
index index.php index.html;
server_name mywebsite.com;
location/{
#rewrite ^(/.*)\.html(\?.*)?$ $1$2 permanent;
try_files $uri $uri/ $uri.php?$args;
}
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
expires 365d;
}
location ~* \.(pdf)$ {
expires 30d;
}
client_max_body_size 3M;
ssl_certificate /etc/letsencrypt/live/mywebsite.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mywebsite.com/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
error_page 403 /index.php;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
access_log /var/log/nginx/www.mywebsite.access.log;
error_log /var/log/nginx/www.mywebsite.error.log;
}
:
は、私は現在、次のconfを持っています。
- クライアントhttps://mywebsite.com/page.phpを要求します:OK
- クライアントがhttps://mywebsite.com/pageを要求:OK
問題は、コード
location/{
try_files $uri $uri/ $uri.php?$args;
}
のこの作品は、2つの場合にうまく機能しているということです
URLを書き換えません!
私が必要とするのは、クライアントがファイル拡張子を持つページにアクセスしようとすると、NGINXがURLを書き換えるように指示することです。たとえば、login.phpを要求すると、nginxは 'login'を書き直します。
また、URLにGETパラメータを保持する必要があります。
私のコードでは、拡張子を持つphpファイルへのリンクを保持し、相対URLではないので(NGINXが書き換えることを望む)、適切なconfは何ですか? (私は私のコードで相対URLを設定する必要がある場合、私は私は私の地元を壊したくないことができます)
[書き換えルールでURLから.phpを削除する](http://stackoverflow.com/questions/19975218/remove-php-from-url-with-rewrite-rule) – aldanux
はい私は指示に従っていますこの投稿では何も働いていませんでした... –