Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update nginx.tmpl #2016

Closed
wants to merge 1 commit into from
Closed

Update nginx.tmpl #2016

wants to merge 1 commit into from

Conversation

anerg2046
Copy link

  • Add VIRTUAL_PROTO=custome

When proto is custome, All location shoud be define in /etc/nginx/vhost.d/, such as /etc/nginx/vhost.d/domain.com_location

That's very usefull when working with php-fpm.

for example of wordpress:

version: '3.1'

networks:
  work-net:
    external: true
      
services:

  wordpress:
    image: wordpress:fpm-alpine
    restart: always
    environment:
      - WORDPRESS_DB_HOST=xx.xx.xx.xx
      - WORDPRESS_DB_USER=dbuser
      - WORDPRESS_DB_PASSWORD=dbpass
      - WORDPRESS_DB_NAME=dbname
      - VIRTUAL_HOST=blog.xxx.com
      - VIRTUAL_PROTO=custome
      - LETSENCRYPT_HOST=blog.xxx.com
      - SHA1_UPSTREAM_NAME=true
    volumes:
      - /data/blog:/var/www/html
    networks:
      - work-net

And we should add a volume in nginx-proxy

docker run -d \
 --restart=always \
 --name nginx-proxy \
 --net work-net \
 -p 80:80 \
 -p 443:443 \
 -v certs:/etc/nginx/certs \
 -v vhost:/etc/nginx/vhost.d \
 -v html:/usr/share/nginx/html \
 -v /var/run/docker.sock:/tmp/docker.sock:ro \
 -v /data/blog:/wordpress \
 nginxproxy/nginx-proxy:alpine

Then add a file blog.xxx.com_location in docker volume vhost with content like this:

root   /wordpress/;
index index.php;

location = /favicon.ico {
    log_not_found off;
    access_log off;
}

location = /robots.txt {
    allow all;
    log_not_found off;
    access_log off;
}

location / {
    try_files $uri $uri/ /index.php?$args;
}

location ~ \.php$ {
    fastcgi_pass    blog.xxx.com;
    fastcgi_param   SCRIPT_FILENAME /var/www/html/$fastcgi_script_name;
    fastcgi_param   PATH_INFO       $fastcgi_path_info;
    fastcgi_index   index.php;
    include         fastcgi_params;
}

location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
    access_log off; 
    log_not_found off; 
    expires max;
}

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
    access_log off; 
    expires max;
    log_not_found off;
}

NOTICE

fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name;

CAN NOT set to fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

because nginx-proxy and php-fpm are TWO Containers

nginx-proxy work for static file in /wordpress and fpm work for php file in /var/www/html

- Add VIRTUAL_PROTO=custome
@buchdag buchdag added status/pr-needs-tests This PR needs new or additional test(s) status/pr-needs-docs This PR needs new or additional documentation type/feat PR for a new feature labels Dec 27, 2022
@buchdag
Copy link
Member

buchdag commented Dec 27, 2022

@anerg2046 thanks for the PR but I'm not comfortable with the idea of adding a value to VIRTUAL_PROTO that is not an actual protocol. I know this is a requested feature and I think I'd rather adapt/rebase #1179 and add tests to it in order to merge this feature.

@buchdag buchdag closed this Dec 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/pr-needs-docs This PR needs new or additional documentation status/pr-needs-tests This PR needs new or additional test(s) type/feat PR for a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants