共享Nginx服务器配置 [英] Share Nginx server configuration
问题描述
如何在两台服务器之间共享通用配置.我的应用程序同时支持http和https(仅几页),并且我目前正在使用fastcgi_param保存敏感信息,例如数据库名称和密码.我如何共享两个服务器的位置和fastcgi_param(80,443).
How can i share common configuration between two servers. My app support both http and https(for few pages) and i am currently using fastcgi_param to save sensitive information like DB name and password. How can i share the location and fastcgi_param for both server(80, 443).
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;
}
}
我要分享的
conf:
conf i want to share:
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服务器块合并为一个-易于维护:
Starting from 0.7.14, you can combine HTTP and HTTPS server blocks into single one - much easier to maintain:
server {
listen 80;
listen 443 ssl;
server_name example.com;
...
}
看一看 http://nginx.org/en/docs/http/configuring_https_servers.html#single_http_https_server 有关详细信息.
Take a look on http://nginx.org/en/docs/http/configuring_https_servers.html#single_http_https_server for details.
这篇关于共享Nginx服务器配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!