我有我的服務器上有多個帳戶/域。我在Apache 2.4上使用cPanel,並希望使用Nginx作爲前端反向代理。我更改了Apache端口,安裝了Nginx並且它工作正常,但僅適用於一個域/帳戶。我想將它用於服務器上的所有域以及任何未來的帳戶。我試圖輸入$domain
變量而不是特定的域,但後來才意識到nginx不支持變量。與用戶目錄相同的東西。下面是我的配置文件:Nginx的多個域
user nobody;
worker_processes 4;
error_log logs/error.log crit;
worker_rlimit_nofile 8192;
events {
worker_connections 1024; # you might need to increase this setting for busy servers
use epoll; # Linux kernels 2.6.x change to epoll
}
http {
server_names_hash_max_size 2048;
server_names_hash_bucket_size 512;
server_tokens off;
include mime.types;
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 10;
# Gzip on
gzip on;
gzip_min_length 1100;
gzip_buffers 4 32k;
gzip_types text/plain application/x-javascript text/xml text/css;
# Other configurations
ignore_invalid_headers on;
client_max_body_size 8m;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
connection_pool_size 256;
client_header_buffer_size 4k;
large_client_header_buffers 4 32k;
request_pool_size 4k;
output_buffers 4 32k;
postpone_output 1460;
# Cache most accessed static files
open_file_cache max=10000 inactive=10m;
open_file_cache_valid 2m;
open_file_cache_min_uses 1;
open_file_cache_errors on;
# virtual hosts includes
include "/etc/nginx/conf.d/*.conf";
server {
# this is your access logs location
access_log /usr/local/apache/domlogs/accountusername/example.com;
error_log logs/vhost-error_log warn;
listen 80;
# change to your domain
server_name example.com www.example.com;
location ~* \.(gif|jpg|jpeg|png|wmv|avi|mpg|mpeg|mp4|htm|html|js|css)$ {
# this is your public_html directory
root /home/accountusername/public_html;
}
location/{
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 16 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
proxy_connect_timeout 30s;
# change to your domain name
proxy_redirect http://www.example.com:8080 http://www.example.com;
proxy_redirect http://example.com:8080 http://example.com;
proxy_pass http://127.0.0.1:8080/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
}
我試圖做的是地方對服務器上的所有域,將添加任何未來域工作的代碼。我看到一些論壇和博客解釋設置虛擬主機(服務器塊),但我不知道他們用於什麼。如果有人提供關於此的任何信息,我將不勝感激。我應該設置虛擬主機嗎?需要在我的配置文件中更改什麼?謝謝。
非常有幫助,非常感謝你:)你知道爲什麼網站圖標顯示不出來?可能缺少一行代碼? – 2014-12-14 15:44:18
我在** server {} **'location = /favicon.ico {log_not_found off; access_log off;}裏面試過這段代碼,但它不起作用。 – 2014-12-14 16:32:41
這是正確的位置。刪除'log_not_found off'並檢查error_log找不到nginx文件。 – 2014-12-14 18:47:22