nginx配置Laravel

前台html服务器,测试的时候不加缓存

server {
        listen  82;
        root   D:/phpStudy/WWW/BCCWap;
        index index.html index.htm;
        location ~ .*\.(css|js|swf|htm|html)$ {
        add_header Cache-Control no-store;
        }
}

php项目,laravel,thinkphp,Ci都用这个

server {
        listen       83;
        root   D:\phpStudy\WWW\xxx\public; 
        index  index.html index.htm index.php;
        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }
        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
}

一般的php项目,例如测试的,非框架

server {
        listen       80;
        server_name  mytest.com test.com;
        root   "D:/phpStudy/WWW/test.com";
        location / {
            index  index.html index.htm index.php;
        }

        location = /favicon.ico {
           log_not_found off;
           access_log off;
         }
         location ~ \.php$ {
             fastcgi_pass   127.0.0.1:9000;
             fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
             include        fastcgi_params;
         }
}

更多可以参考:
https://github.com/daylerees/laravel-website-configs

apache:

<VirtualHost *:80>

    # Host that will serve this project.
    ServerName      app.dev

    # The location of our projects public directory.
    DocumentRoot    /path/to/our/public

    # Useful logs for debug.
    CustomLog       /path/to/access.log common
    ErrorLog        /path/to/error.log

    # Rewrites for pretty URLs, better not to rely on .htaccess.
    <Directory /path/to/our/public>
        <IfModule mod_rewrite.c>
            Options -MultiViews
            RewriteEngine On
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteRule ^ index.php [L]
        </IfModule>
    </Directory>

</VirtualHost>

nginx:

server {

    # Port that the web server will listen on.
    listen          80;

    # Host that will serve this project.
    server_name     app.dev;

    # Useful logs for debug.
    access_log      /path/to/access.log;
    error_log       /path/to/error.log;
    rewrite_log     on;

    # The location of our projects public directory.
    root            /path/to/our/public;

    # Point index to the Laravel front controller.
    index           index.php;

    location / {

        # URLs to attempt, including pretty ones.
        try_files   $uri $uri/ /index.php?$query_string;

    }

    # Remove trailing slash to please routing system.
    if (!-d $request_filename) {
        rewrite     ^/(.+)/$ /$1 permanent;
    }

    # PHP FPM configuration.
    location ~* \.php$ {
            fastcgi_pass                    unix:/var/run/php5-fpm.sock;
            fastcgi_index                   index.php;
            fastcgi_split_path_info         ^(.+\.php)(.*)$;
            include                         /etc/nginx/fastcgi_params;
            fastcgi_param                   SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    # We don't need .ht files with nginx.
    location ~ /\.ht {
            deny all;
    }
    
    # Set header expirations on per-project basis
    location ~* \.(?:ico|css|js|jpe?g|JPG|png|svg|woff)$ {
            expires 365d;

    }
}

lighttpd:

$HTTP["host"] =~ "example.com$" {
        server.document-root = "/path/to/our/public/"
        accesslog.filename = "/path/to/access.log"

        alias.url = ()
        url.redirect = ()
        url.rewrite-once = (
                "^/(css|img|js|fonts)/.*\.(jpg|jpeg|gif|png|swf|avi|mpg|mpeg|mp3|flv|ico|css|js|woff|ttf)$" => "$0",
                "^/(favicon\.ico|robots\.txt|sitemap\.xml)$" => "$0",
                "^/[^\?]*(\?.*)?$" => "index.php/$1"
        )
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
要在Docker中部署Laravel应用程序,你可以使用以下步骤: 1. 首先,在你的Laravel项目根目录下创建一个名为`Dockerfile`的文件,并添加以下内容: ``` # 使用官方的PHP镜像作为基础镜像 FROM php:7.4-fpm # 安装一些必要的依赖 RUN apt-get update && apt-get install -y \ git \ unzip \ libpng-dev \ libonig-dev \ libxml2-dev \ zip \ curl # 安装Composer RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer # 设置工作目录 WORKDIR /var/www # 复制项目文件到工作目录 COPY . /var/www # 安装项目依赖 RUN composer install --no-interaction --optimize-autoloader # 设置文件夹权限 RUN chown -R www-data:www-data /var/www/storage /var/www/bootstrap/cache # 生成应用密钥 RUN php artisan key:generate # Expose port 9000 and start php-fpm server EXPOSE 9000 CMD ["php-fpm"] ``` 2. 创建一个名为`docker-compose.yml`的文件,并添加以下内容: ``` version: '3' services: app: build: context: . dockerfile: Dockerfile image: laravel-app container_name: laravel-app restart: unless-stopped ports: - 8000:9000 volumes: - .:/var/www networks: - laravel nginx: image: nginx:latest container_name: laravel-nginx restart: unless-stopped ports: - 80:80 volumes: - .:/var/www - ./nginx.conf:/etc/nginx/conf.d/default.conf networks: - laravel networks: laravel: ``` 3. 在你的Laravel项目根目录下创建一个名为`nginx.conf`的文件,并添加以下内容: ``` server { listen 80; index index.php index.html; server_name localhost; error_log /var/log/nginx/error.log; access_log /var/log/nginx/access.log; root /var/www/public; location / { try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$ { try_files $uri /index.php =404; fastcgi_pass app:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; } } ``` 4. 确保你的Laravel项目根目录下有一个`.env`文件,其中包含正确的数据库连接和其他配置。 5. 在项目根目录中运行以下命令以构建和启动容器: ``` docker-compose up -d --build ``` 这将构建并启动包含Laravel应用程序和Nginx服务器的Docker容器。 6. 在浏览器中访问`http://localhost`,你应该能够看到你的Laravel应用程序运行在Docker容器中。 这就是在Docker中部署Laravel应用程序的基本步骤。你可以根据需要进行修改和调整。希望对你有帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

SHUIPING_YANG

你的鼓励是我创作的最大动力。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值