问题描述
我正在尝试优化我的服务器 Nginx 性能,但我不知道如何优化。 我的服务器是 ubuntu 20.04,我在本地安装了一个 Nginx,并用它来反向代理到我的 2 个网站。
我用于重定向到 website1 的原生 Nginx 配置是这样的:
server {
listen 80; listen [::]:80;
server_name website1.com www.website1.com;
location / {
client_max_body_size 5M; # --> Maximum 5MB file is allowed to upload
proxy_pass http://127.0.0.1:9191/;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
}
并且网站 1 设置了以下 docker-compose 文件:
version: "3.7"
services:
# Database for wordpress MysqL
MysqL_db:
image: MysqL:8.0
container_name: MysqL
restart: unless-stopped
env_file: .env
environment:
- MysqL_DATABASE=db_name
volumes:
- db:/var/lib/MysqL
command: '--default-authentication-plugin=MysqL_native_password'
networks:
- ntk
# wordpress service
wordpress:
depends_on:
- MysqL_db
- redis
image: wordpress:fpm-alpine
container_name: wordpress
restart: unless-stopped
env_file: .env
environment:
- wordpress_DB_HOST=MysqL_db:3308
- wordpress_DB_USER=$MysqL_USER
- wordpress_DB_PASSWORD=$MysqL_PASSWORD
- wordpress_DB_NAME=stsecret_db_name
- wordpress_CONfig_EXTRA=
define('WP_REdis_HOST','redis');
define('WP_REdis_PORT','9649');
define('wp_cache_KEY_SALT','password');
define('wp_cache','true');
volumes:
- wp:/var/www/html
networks:
- ntk
# Nginx webserver
Nginx:
depends_on:
- wordpress
image: Nginx:alpine
container_name: Nginx
restart: unless-stopped
ports:
- 9191:80
volumes:
- ./Nginx-conf:/etc/Nginx/conf.d
- wp:/var/www/html
networks:
- ntk
# Redis
redis:
image: redis:alpine
container_name: redis
restart: unless-stopped
ports:
- 9649:9649
volumes:
- rd:/var/www/html
networks:
- ntk
entrypoint: redis-server --maxmemory 256mb --maxmemory-policy allkeys-lru
volumes:
db:
wp:
rd:
networks:
ntk:
driver: bridge
以及传递的 website1 的 docker Nginx 配置:
server {
listen 80;
listen [::]:80;
server_name server_name website1.ir www.website1.ir;
# Gzip configuration
gzip on;
gzip_static on; # allows pre-serving of .gz file if it exists
gzip_disable "msie6"; # disable for user-agent Internet explorer 6. Not supported.
gzip_proxied any; # enable gzip for all proxied requests
gzip_buffers 16 8k; # number and size of buffers to compress a response
gzip_http_version 1.1;
gzip_min_length 256; # Only gzip files of size in bytes
gzip_types text/plain text/css text/html application/javascript application/json application/x-javascript text/xml application/xml application/xml+RSS text/javascript $
gunzip on; # Uncompress on the fly
# wordpress
location / {
client_max_body_size 20M;
index index.PHP index.html index.htm;
root /var/www/html;
try_files $uri $uri/ /index.PHP$is_args$args;
}
location ~ \.PHP$ {
client_max_body_size 20M;
index index.PHP index.html index.htm;
root /var/www/html;
try_files $uri =404;
fastcgi_split_path_info ^(.+\.PHP)(/.+)$;
fastcgi_pass wordpress:9000;
fastcgi_index index.PHP;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PHP_VALUE "upload_max_filesize=128M \n post_max_size=128M";
}
}
我想根据这个 tutorial 修改我的 Nginx,但我有两个问题找不到答案。
-
即使现在一切正常,但使用 2 个 Nginx 不是多余的吗?我的意思是,我可以使用本地安装的 Nginx 并摆脱 docker Nginx 吗?如果是,如何?我尝试在没有 Nginx 的情况下运行 docker-compose 并将 wordpress 9191 端口暴露给外部,因此 Nginx 可以直接重定向到它,但它不起作用!
-
如果必须使用 2 个 Nginx,我应该在哪里添加本 tutorial 中提到的内容,例如微缓存、Pagespeed 模块和速率限制?应该添加到本地 Nginx 还是 docker 内部?
谢谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)