laravel 如何在ubuntu中使用nginx设置服务器?

jk9hmnmh  于 2023-03-09  发布在  Nginx
关注(0)|答案(1)|浏览(137)

我的域名是www.example.com,nginx文件如下所示,所以我的根路径是/var/www/campaignmanager/bannerad/public。example.com and nginx file like below. So my root path is /var/www/campaignmanager/bannerad/public.
因此,我的域在浏览器中打开,如www.example.com,但我想打开它,如example. com/campaignmanagerwww. example. com/campaignmanagerexample.com but i want to open it likeexample.com/campaignmanagerorwww.example.com/campaignmanager
请帮帮我。

server { 
    listen 80; 
    listen [::]:80;

    root /var/www/campaignmanager/bannerad/public;

    index index.php index.html index.htm;

    server_name exmaple.com www.example.com;

    location / {
      try_files $uri $uri/index.html $uri.html @upstream;
    }

    location @upstream {
     location ~ \.php$ {
       try_files $uri /index.php =404;
       fastcgi_split_path_info ^(.+\.php)(/.+)$;
       fastcgi_pass unix:/run/php/php7.1-fpm.sock;
       fastcgi_index index.php;
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
       include fastcgi_params;
     }
   }
}
cbwuti44

cbwuti441#

您可以结合使用server和location指令来完成此操作。

server { 
        listen 80; 
        listen [::]:80;

        root /var/www/campaignmanager/bannerad/public;

        index index.php index.html index.htm;

        server_name exmaple.com/sample

        location /sample {
          try_files $uri $uri/index.html $uri.html @upstream;
        }

        location @upstream {
         location ~ \.php$ {
           try_files $uri /index.php =404;
           fastcgi_split_path_info ^(.+\.php)(/.+)$;
           fastcgi_pass unix:/run/php/php7.1-fpm.sock;
           fastcgi_index index.php;
           fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
           include fastcgi_params;
         }
       }
    }

请原谅语法错误。https://www.keycdn.com/support/nginx-location-directive/http://nginx.org/en/docs/http/server_names.html

相关问题