Nginx配置文件示類

一、配置介紹

# For more information on configuration, see:
		#   * Official English Documentation: http://nginx.org/en/docs/
		#   * Official Russian Documentation: http://nginx.org/ru/docs/

		user nginx;
		worker_processes auto;  # nginx工作進程數,根據cpu的核數定義
		error_log /var/log/nginx/error.log;  # 
		pid /run/nginx.pid;

		# Load dynamic modules. See /usr/share/nginx/README.dynamic.
		include /usr/share/nginx/modules/*.conf;

		events {
			worker_connections 1024;  # 連接數
		}

		# 定義nginx的核心web功能
		http {
			log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '   # 定義日誌格式 
							  '$status $body_bytes_sent "$http_referer" '
							  '"$http_user_agent" "$http_x_forwarded_for"';

			# access_log  /var/log/nginx/access.log  main;  # 開啓訪問日誌功能的參數

			sendfile            on;
			tcp_nopush          on;
			tcp_nodelay         on;
			keepalive_timeout   65;  # 保持鏈接連接時長
			types_hash_max_size 2048;  # 

			include             /etc/nginx/mime.types;
			default_type        application/octet-stream;
			gzip on; # 啓動壓縮模式
			# Load modular configuration files from the /etc/nginx/conf.d directory.
			# See http://nginx.org/en/docs/ngx_core_module.html#include
			# for more information.
			include /etc/nginx/conf.d/*.conf;
			   upstream django {
				# 連接到Django的端口號, 和uwsgi.ini文件中端口一致. 127.0.0.1說明只允許本地轉發
				 server 127.0.0.1:8001; # for a web port socket (we'll use this first
				 }
				 
				 
				 
			server {
				listen       80;  # 定義nginx的入口端口是80端口
				server_name  47.100.106.169;  # 服務器域名或ip
				charset     utf-8;  # 定義編碼
				access_log      /home/chengjian-env/python_tx晨檢/nginx_access.log;  # 自定義日誌文件
				error_log       /home/chengjian-env/python_tx晨檢/nginx_error.log;
				client_max_body_size 75M;
				location /static {
					alias /home/chengjian-env/python_tx晨檢/static; # your Django project's static files - amend as required
				}
				# 用戶請求是 47.100.106.169/
				location / { 
					# root html  # 定義網頁根目錄(定義虛擬主機的根目錄)
					uwsgi_pass  django;
					# index index.html  # 定義網頁的首頁文件的名字
					include     /home/chengjian-env/python_tx晨檢/uwsgi_params; # the uwsgi_params file you installed
				}
				# error_page 404 /404.html;  # 配置錯誤頁面
				# error_page 500 502 503 504 /50x.html; 

			}
			
			
			#  開啓一個虛擬nginx主機
			server {
				listen       80;  # 定義nginx的入口端口是80端口
				server_name  www.lilongfei.com;  # 服務器域名或ip
				charset     utf-8;  # 定義編碼
				access_log      /home/chengjian-env/python_tx晨檢/nginx_access.log;  # 自定義日誌文件
				error_log       /home/chengjian-env/python_tx晨檢/nginx_error.log;
				client_max_body_size 75M;
				location /static {
					alias /home/chengjian-env/python_tx晨檢/static; # your Django project's static files - amend as required
				}
				# 用戶請求是 47.100.106.169/
				location / { 
					# deny 192.168.1.1  #  封掉192.168.1.1
					# root html  # 定義網頁根目錄(定義虛擬主機的根目錄)
					uwsgi_pass  django;
					# index index.html  # 定義網頁的首頁文件的名字
					include     /home/chengjian-env/python_tx晨檢/uwsgi_params; # the uwsgi_params file you installed
				}
				# error_page 404 /404.html;  # 配置錯誤頁面
				# error_page 500 502 503 504 /50x.html; 

			}
			
			
			

		# Settings for a TLS enabled server.
		#
		#    server {
		#        listen       443 ssl http2 default_server;
		#        listen       [::]:443 ssl http2 default_server;
		#        server_name  _;
		#        root         /usr/share/nginx/html;
		#
		#        ssl_certificate "/etc/pki/nginx/server.crt";
		#        ssl_certificate_key "/etc/pki/nginx/private/server.key";
		#        ssl_session_cache shared:SSL:1m;
		#        ssl_session_timeout  10m;
		#        ssl_ciphers HIGH:!aNULL:!MD5;
		#        ssl_prefer_server_ciphers on;
		#
		#        # Load configuration files for the default server block.
		#        include /etc/nginx/default.d/*.conf;
		#
		#        location / {
		#        }
		#
		#        error_page 404 /404.html;
		#            location = /40x.html {
		#        }
		#
		#        error_page 500 502 503 504 /50x.html;
		#            location = /50x.html {
		#        }
		#    }

		}

二、docker容器中的配置示例

server {
	listen 80;
	listen 443 ssl;
	server_name  192.168.0.189;
	charset     utf-8;
    	ssl_certificate /home/project/nginx-conf/ssl/3485948_lilongfei.top.pem;
    	ssl_certificate_key /home/project/nginx-conf/ssl/3485948_lilongfei.top.key;
    	ssl_session_timeout 5m;
    	ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 
    	ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
    	ssl_prefer_server_ciphers on;
	access_log      /home/project/blog/block/logs/nginx-logs/nginx_access.log;
	error_log       /home/project/blog/block/logs/nginx-logs/nginx_error.log;
	client_max_body_size 75M;
	proxy_intercept_errors on;
	if ($scheme = http) {
		return 301 https://lilongfei.top$request_uri;
	}	
	location /static {
		alias /home/project/blog/static/;
		break;
	}
	location /media {
		alias /home/project/blog/media/;
		expires 30d;
	
	}
	location / {
                proxy_pass http://192.168.0.189:8081;
                proxy_set_header Host $host;
                proxy_redirect off;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
	}
    	error_page 404 /404.html;
	location = /404.html {
		root /home/project/nginx-conf/404.error;
	}
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章