gpt4 book ai didi

php - 分享 Nginx 服务器配置

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:02:46 24 4
gpt4 key购买 nike

如何在两台服务器之间共享通用配置。我的应用程序同时支持 http 和 https(只有几页),我目前正在使用 fastcgi_param 来保存敏感信息,例如数据库名称和密码。我如何共享两个服务器(80、443)的位置和 fastcgi_param。

server {    listen 80;    server_name example.com;}server {    listen 443 ssl;    server_name example.com;    root /home/forge/example.com/public;    # FORGE SSL (DO NOT REMOVE!)    ssl on;    ssl_certificate /etc/nginx/ssl/example.com/304/server.crt;    ssl_certificate_key /etc/nginx/ssl/example.com/304/server.key;    index index.html index.htm index.php;    charset utf-8;    location / {        try_files $uri $uri/ /index.php?$query_string;    }    location = /favicon.ico { access_log off; log_not_found off; }    location = /robots.txt  { access_log off; log_not_found off; }    access_log off;    error_log  /var/log/nginx/example.com-error.log error;    error_page 404 /index.php;    location ~ \.php$ {        fastcgi_param ENV "production";        fastcgi_param DB_HOST "127.0.0.1";        fastcgi_param DB_PASSWORD "123456";        fastcgi_param DB_USERNAME "user";        fastcgi_param DB_NAME "example";        fastcgi_split_path_info ^(.+\.php)(/.+)$;        fastcgi_pass unix:/var/run/php5-fpm.sock;        fastcgi_index index.php;        include fastcgi_params;    }    location ~ /\.ht {        deny all;    }}

我想分享的配置:

index index.html index.htm index.php;    charset utf-8;    location / {        try_files $uri $uri/ /index.php?$query_string;    }    location = /favicon.ico { access_log off; log_not_found off; }    location = /robots.txt  { access_log off; log_not_found off; }    access_log off;    error_log  /var/log/nginx/example.com-error.log error;    error_page 404 /index.php;    location ~ \.php$ {        fastcgi_param ENV "production";        fastcgi_param DB_HOST "127.0.0.1";        fastcgi_param DB_PASSWORD "123456";        fastcgi_param DB_USERNAME "user";        fastcgi_param DB_NAME "example";        fastcgi_split_path_info ^(.+\.php)(/.+)$;        fastcgi_pass unix:/var/run/php5-fpm.sock;        fastcgi_index index.php;        include fastcgi_params;    }    location ~ /\.ht {        deny all;    }

最佳答案

从 0.7.14 开始,您可以将 HTTP 和 HTTPS 服务器 block 合并为一个 - 更易于维护:

server {
listen 80;
listen 443 ssl;
server_name example.com;
...
}

看看 http://nginx.org/en/docs/http/configuring_https_servers.html#single_http_https_server了解详情。

关于php - 分享 Nginx 服务器配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24154451/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com