Nginx 配置

t****@laravel-docker-t****:~/***api/***s-api/docker-compose/nginx$ cat ***api.conf
server {
    listen 80;
    index index.php index.html;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /var/www/public;
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass app:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
    location / {
        try_files $uri $uri/ /index.php?$query_string;
        gzip_static on;
    }
}


t****@laravel-docker-t****:~/***api/***s-api/docker-compose/nginx$ docker exec -it ***api-nginx sh
/ # [30;5Rll <<<注意这个是按下键盘自动加了[30;5R 当时没注意,输入ll就成了这样
sh: [30: not found
sh: 5Rll: not found
/ # [30;5Rls  <<<注意这个是按下键盘自动加了[30;5R 当时没注意,输入ls就成了这样
sh: [30: not found
sh: 5Rls: not found
/ # ls
bin                   etc                   mnt                   run                   tmp
dev                   home                  opt                   sbin                  usr
docker-entrypoint.d   lib                   proc                  srv                   var
docker-entrypoint.sh  media                 root                  sys
/ # ll
sh: ll: not found
/ # cd var/www/                                                                                                     /var/www # ll                                                                                                       sh: ll: not found                                                                                                   /var/www # ls                                                                                                           Dockerfile               composer.lock            package.json             storage                                  README.md                config                   phpunit.xml              tests                                    app                      database                 public                   vendor                                   artisan                  docker-compose           resources                webpack.mix.js                           bootstrap                docker-compose.prod.yml  routes                                                            composer.json            package-lock.json        server.php                                
/var/www # cd ../etc                                                                                                sh: cd: can't cd to ../etc: No such file or directory                                                               /var/www # cd ~                                                                                                     ~ # cd /                                                                                                            / # ls                                                                                                              bin                   etc                   mnt                   run                   tmp
dev                   home                  opt                   sbin                  usr
docker-entrypoint.d   lib                   proc                  srv                   var
docker-entrypoint.sh  media                 root                  sys
/ # cd etc/nginx/
/etc/nginx # ls
conf.d          fastcgi_params  koi-win         modules         scgi_params     win-utf
fastcgi.conf    koi-utf         mime.types      nginx.conf      uwsgi_params
/etc/nginx # cat nginx.conf

user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}
/etc/nginx # cd conf.d/                                                                                             /etc/nginx/conf.d # ls                                                                                              ***api.conf                                                           
/etc/nginx/conf.d # [43;21R         


可以结合docker-compose.yml一起看:

version: "3.7"
services:
  app:
    build:
      args:
        user: ***api
        uid: 1000
      context: ./
      dockerfile: Dockerfile
    image: ***apii
    container_name: ***api-app
    restart: unless-stopped
    working_dir: /var/www/
    volumes:
      - ./:/var/www
    networks:
      - ***apin
  db:
    image: mysql:5.7 #请注意有的情况是需要考虑mysql安装后的初始密码问题的,有的是空密有的是生成密码,
                     #所以需要更改,但我们docker这里配置的environment里设置好了,就是OK的
    container_name: ***api-db
    restart: unless-stopped
    environment:
      MYSQL_DATABASE: ${DB_DATABASE}#于.env中读取 
      MYSQL_ROOT_PASSWORD: ${DB_PASSWORD} #与下同
      MYSQL_PASSWORD: ${DB_PASSWORD} #实际采用了7K*************z
      MYSQL_USER: ${DB_USERNAME} #实际采用了 root***
      SERVICE_TAGS: dev
      SERVICE_NAME: mysql
    volumes:
      - ./docker-compose/mysql:/docker-entrypoint-initdb.d
    networks:
      - ***apin
  nginx:
    image: nginx:1.19.1-alpine
    container_name: ***api-nginx
    restart: unless-stopped
    ports:
      - “80:80"
    volumes:
      - ./:/var/www
      - ./docker-compose/nginx:/etc/nginx/conf.d
    networks:
      - ***apin
networks:
  ***apin:
    driver: bridge

可以学习: Nginx(二)------nginx.conf 配置文件 

Nginx(三)------nginx 反向代理

Nginx(四)------nginx 负载均衡

posted @ 2020-07-15 02:48  dzkjz  阅读(181)  评论(0编辑  收藏  举报