Nginx ルートディレクトリの末尾にスラッシュ

このQ&Aのポイント
  • Nginx 1.10.0にて、example.comにアクセスするとexample.com/にリダイレクトされます。
  • この末尾のトレイリングスラッシュを取り除きたいです。
  • Nginx.confの設定ファイルを確認しましょう。
回答を見る
  • ベストアンサー

Nginx ルートディレクトリの末尾にスラッシュ

Nginx 1.10.0にて、example.comにアクセスするとexample.com/にリダイレクトされます。この末尾のトレイリングスラッシュを取り除きたいです。 設定ファイルは以下の通りです。 Nginx.conf ===== user www-data; worker_processes auto; pid /run/nginx.pid; events { worker_connections 768; # multi_accept on; } http { ## # Basic Settings ## sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; # server_tokens off; # server_names_hash_bucket_size 64; # server_name_in_redirect off; include /etc/nginx/mime.types; default_type application/octet-stream; ## # SSL Settings ## ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE ssl_prefer_server_ciphers on; ## # Logging Settings ## access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; ## # Gzip Settings ## gzip on; gzip_disable "msie6"; # gzip_vary on; # gzip_proxied any; # gzip_comp_level 6; # gzip_buffers 16 8k; # gzip_http_version 1.1; # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; ## # Virtual Host Configs ## include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; } #mail { # # See sample authentication script at: # # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript # # # auth_http localhost/auth.php; # # pop3_capabilities "TOP" "USER"; # # imap_capabilities "IMAP4rev1" "UIDPLUS"; # # server { # listen localhost:110; # protocol pop3; # proxy on; # } # # server { # listen localhost:143; # protocol imap; # proxy on; # } #} sites-enabled/default === ## # You should look at the following URL's in order to grasp a solid understanding # of Nginx configuration files in order to fully unleash the power of Nginx. # http://wiki.nginx.org/Pitfalls # http://wiki.nginx.org/QuickStart # http://wiki.nginx.org/Configuration # # Generally, you will want to move this file somewhere, and start with a clean # file but keep this around for reference. Or just disable in sites-enabled. # # Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples. ## # Default server configuration # server { listen 80 default_server; listen [::]:80 default_server; # SSL configuration # # listen 443 ssl default_server; # listen [::]:443 ssl default_server; # # Note: You should disable gzip for SSL traffic. # See: https://bugs.debian.org/773332 # # Read up on ssl_ciphers to ensure a secure configuration. # See: https://bugs.debian.org/765782 # # Self signed certs generated by the ssl-cert package # Don't use them in a production server! # # include snippets/snakeoil.conf; root /var/www/html; # Add index.php to the list if you are using PHP index index.php index.html index.htm index.nginx-debian.html; server_name example.com; location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { include snippets/fastcgi-php.conf; # # # With php7.0-cgi alone: # fastcgi_pass 127.0.0.1:9000; # # With php7.0-fpm: fastcgi_pass unix:/run/php/php7.1-fpm.sock; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # Virtual Host configuration for example.com # # You can move that to a different file under sites-available/ and symlink that # to sites-enabled/ to enable it. # #server { # listen 80; # listen [::]:80; # # server_name example.com; # # root /var/www/example.com; # index index.html; # # location / { # try_files $uri $uri/ =404; # } #}

質問者が選んだベストアンサー

  • ベストアンサー
回答No.1

よく分かりませんが、ここのコメントアウトを有効にしてみてはどうでしょうか。 # server_name_in_redirect off;

digda_mc
質問者

お礼

うまく動きました!ありがとうございました!

関連するQ&A

  • FastCGI ーPHPで、同時アクセスができない

    環境、nginx Ver1.52, php Ver5.4.17, OS Windows7、ブラウザ:FireFox nginx の場合、phpはFastCGIで動作します。 同じ内容の 1.php 2.php, それぞれ表示します。 ーーー <?php echo date('h:i:s A -> ... -> '); sleep(5); echo date('h:i:s A '); ?> ーーー 1.php 08:12:21 AM -> ... -> 08:12:26 AM 2.php 08:12:26 AM -> ... -> 08:12:31 AM 結果は上記のとおり、必ず1.phpが終了してから、2.phpが実行されます。 nginx の conf php.ini は doc_root ぐらいしか変えていません。 デフォルトのままです。 lightHttpd + PHP (FastCGI) でも同じ結果です。 lightHttpd + PHP (CGI) だったら、同時に実行できます。 これはWindows版のFastCGIのPHPのバグでしょうか。 それとも、どこかに設定があるのでしょうか。 よろしくお願いします。

    • 締切済み
    • PHP
  • Laravelを80で表示するには

    表題の件で質問いたします 環境は以下の通りとなります。 ************************************ [環境] CentOS 7.5 nginx 1.15 php-fpm 7.2.8 Laravel 5.6 80番ポート開放済み SELinuxは停止済み ************************************ デフォルト8000番が確認できてからやったこと ・nginx 80→8000に変更 ・Laravel vendor/laravel/framework/src/Illuminate/Foundation/Console/ServeCommand.php 8000→80に変更 以下のコマンドを実施 php -S 0.0.0.0:80 public/ 実行結果 PHP 7.2.8 Development Server started at Sun Aug 5 10:37:14 2018 Listening on http://0.0.0.0:80 Document root is /var/www/html/example Press Ctrl-C to quit. ブラウザの結果 このサイトにアクセスできません 160.16.94.174 からの応答時間が長すぎます。 example public を Google で検索してください ERR_CONNECTION_TIMED_OUT 上記の結果まではたどり着きましたが、何かが足りないのかなと 思っております。 解決策をご教示頂けないでしょうか。

  • apacheのディレクトリ

    Linux RedHat9をインストールする際に、パッケージでWebサーバーを選択していれた場合、apacheの本体はどのディレクトリ内にインストールされるのでしょうか? Webサーバを選択した場合、PHPもインストールされますが、今回デフォルトでインストールされるPHPは使用できないので、PHPを入れなおしたいのですが、コンフィグレーションする際に、以下のようにapacheのディレクトリを指定したいのですが、どこにあるのか分かりません。 よろしくお願いします。 --with-apxs2=/usr/local/apache2/bin/apxs \

  • ワードプレスのディレクトリ

    ワードプレスのブログ表示先を独自ドメインにしたいのですが、index.phpを表示したいアドレスに書き換えて、htaccessもパーマリンク設定の1番下に出てくるソースに書き換えました。すると、 Warning: require(./○○○.com/wp-blog-header.php) [function.require]: failed to open stream: No such file or directory in /virtual/○○/public_html/○○○.com/index.php on line 4 Fatal error: require() [function.require]: Failed opening required './○○○.com/wp-blog-header.php' (include_path='.:/usr/local/lib/php') in /virtual/○○/public_html/○○○.com/index.php on line 4 こんなエラー画面になります。 どなたかわかるかたいらっしゃいましたら、 よろしくお願いします。 ○のところはサーバーネームと独自ドメインなので、伏字にさせてもらってます。

  • これでサブディレクトリーにならないのですか?

    いつも大変お世話になり、誠にありがとうございます。 標記の件。 初期状態に#を付けております。      記 <VirtualHost *:80> # The ServerName directive sets the request scheme, hostname and port that # the server uses to identify itself. This is used when creating # redirection URLs. In the context of virtual hosts, the ServerName # specifies what hostname must appear in the request's Host: header to # match this virtual host. For the default virtual host (this file) this # value is not decisive as it is used as a last resort host regardless. # However, you must set it for any further virtual host explicitly. #ServerName www.xxxxxxxxxx.com #ServerAdmin hop7799@xxx.xxxx.xx #DocumentRoot /var/www/html # Ensure that Apache listens on port 80 Listen 80 # Listen for virtual host requests on all IP addresses NameVirtualHost *:80 <VirtualHost *:80> DocumentRoot /www/html ServerName www.xxxxxxxxxx.com/content1 # Other directives here </VirtualHost> <VirtualHost *:80> DocumentRoot /www/html ServerName www.xxxxxxxxxx.com/content2 Alias /content2 "/var/www/html/content2/" # Other directives here </VirtualHost> # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, # error, crit, alert, emerg. # It is also possible to configure the loglevel for particular # modules, e.g. #LogLevel info ssl:warn ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined # For most configuration files from conf-available/, which are # enabled or disabled at a global level, it is possible to # include a line for only one particular virtual host. For example the # following line enables the CGI configuration for this host only # after it has been globally disabled with "a2disconf". #Include conf-available/serve-cgi-bin.conf </VirtualHost> # vim: syntax=apache ts=4 sw=4 sts=4 sr noet 以上です。 宜しくお願い申し上げます。

  • どんなディレクトリでもindex.phpへ飛ばす

    http://ドメイン/abc/ http://ドメイン/eee123/ http://ドメイン/xyz/ このようにドメイン直下でどんなディレクトリが指定されても index.phpに飛ばして処理できるようにしたいのですが、 一般的にはどのような方法が使われているのでしょうか。 とりあえず下のようなリダイレクトをやってみたのですが、 index.php用のcssが読み込めなくなってしまいます。 RewriteEngine on RewriteRule ^(.*)$ index.php [L] (おそらくcssもリダイレクトしてしまっている) レンタルサーバなのでapache設定は.htaccessには 書き込めますが、httpd.confには書き込めません。 ちなみに目的は指定されたディレクトリ名で データベースを検索するなどします。

  • Apacheでphpの動作確認ができない

    本日モデムの交換をしてその後から Apache2.4でphpの動作確認ができなくなりました 例えば; www.example.com/test.php ファイルを読み込ませようとすると Forbidden You don't have permission to access /index.php on this server. とでてしまいます モデムの交換前と後では特に設定はいじっていないので モデムの交換でポート番号の再設定などもしっかりと行っています どのように直せばいいのかよろしくお願いします

  • 502 Bad Gatewayの解決方法

     趣味と学習目的で自宅サーバを管理してます。外部公開はしてません。  先ほど自分のサイトにアクセスしたところ、502 Bad Gatewayエラーが発生しました。 HTMLファイルには問題なく接続出来ます。PHPでエラーが発生しました。  nginxのエラーログは下記の通りです。 2013/06/17 23:49:43 [error] 1262#0: *31 kevent() reported that connect() failed (61: Connection refused) while connecting to upstream, client: 192.168.X.X, server: localhost, request: "GET /phpinfo.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "example.com"  ※一部改変しています これはこの問題の最初のエラーログでこのログの下に同じようなログが大量に続いていました。 サーバ設定は FreeBSD で nginx + PHP FPM + fcgiwrap とgoogle検索して、一番上にあるサイトを参考にしました。 そして、今日まで問題なく動作していました。 … しかし、先ほど突然エラーが発生しました。今ままで正常に動作していたのですが…webサーバ関係の設定は変更した覚えがありません。 2013/06/17 23:49:43 より前に行った記憶がsambaの導入なのでそれしか思い当たりがありません。 samba停止や、サーバ再起動を行いましたがダメでした。 検索しても情報が少なく、エラーログを確認してもよくわからなかったので質問しました。 外部公開してないので、すぐ解決する必要はありませんが優しく教えていただけると幸いです。 補足が必要であれば書きます。あと、カテ違いだったらすいません。 長文、乱文失礼しました。

    • ベストアンサー
    • PHP
  • 書き忘れました。

    どこまで安全性を信頼できるのでしょうか? http://www.verisign.com/ssl/index.html VeriSign is the #1 name in Internet trust. Over 90% of secure Web sites worldwide use VeriSign Secure Server IDs to authenticate themselves and to enable SSL encryption to protect sensitive data and transactions. This Web site is secured by a VeriSign SSL certificate. Web sites displaying the TRUSTe Privacy Seal are committed to abiding by a privacy policy that gives users notice, choice, access, security, and redress with regard to their personal information. SSL Certificates TRUSTe is an independent, non-profit initiative dedicated to enabling individuals and organizations to establish trusting relationships based on respect for personal identity and information in the evolving networked world.

  • サブドメインとmod_rewrite

    あるレンタルサーバーで独自ドメインでサイトを運営していますが、以下のようなサブドメインの扱いを実現できる方法を探しています。 使用している独自ドメイン example.com 構成 /home/user01/www/index.html /example/index.php レンタルサーバーのエイリアス設定で「example.com」または「www.example.com」で/example/index.phpを表示するよう設定。 やりたいこと ブラウザのアドレスバーへ入力 → 実際のURL(飛ばし先) http://user.example.com/ → http://example.com/index.php?p=user http://abcd.example.com/ → http://example.com/index.php?p=abcd サブドメインは事実上クエリーなので、userの場合はとかabcdの場合はといった、事前定義的なものができません。 レンタルサーバーのためバーチャルホストは使えません。htaccessとmod_rewriteは使用可能なため、なんとかこれらで実現できないかと考えています。 これに近いことができるという表記が http://www.kawaz.jp/pukiwiki/?mod_rewrite#w1eddb33 にありましたが、自分の環境で試したところ「サーバーが見つかりません」と表示されうまく動きませんでした。最後の改行とか、そのへんのところは大丈夫です。 詳しい方、教えていただけないでしょうか。よろしくおねがいします。