nginx 反向代理apache2、php-fpm、uwsgi配置

一、nginx反向代理配置样例

#user  nobody;
worker_processes  4;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;
worker_rlimit_nofile 65535;

events {
    use epoll;
    worker_connections  4096;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  180;
    client_max_body_size 500m;
    #gzip  on;
    #反向代理到Apache2
    server
	{
		listen 80;
		server_name eblog.com;
		location / {
			proxy_set_header Host $host;
			proxy_set_header X-Real-IP $remote_addr;
			proxy_set_header REMOTE-HOST $remote_addr;
			proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
			proxy_pass http://127.0.0.1:8888;
		}
	}
	#反向代理,Apache2通过mod_php模式执行php代码
	server
	{
			listen 80;
			server_name shop.com test.com;
			location / {
					proxy_set_header Host $host;
					proxy_set_header X-Real-IP $remote_addr;
					proxy_set_header REMOTE-HOST $remote_addr;
					proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
					proxy_pass http://127.0.0.1:8888;
			}
	}
	#反向代理,并使用php-fpm进程模式执行php代码
    server{
		listen	80;
		server_name api.com;
		index index.php;
		root /var/www/yaf_api/public;
		if (!-e $request_filename) {
			rewrite ^/(.*)  /index.php?$1 last;
		}

		location ~ .php$ {
			fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
			fastcgi_index index.php;
			fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
			include fastcgi_params;
		}
		access_log /var/log/yaf_api/yaf.api.log;
	}
	
	#反向代理到python
	server 
	{
			listen       80;
			server_name  webchat.com;
			
			location / {           
			root /var/www/webchat;
				include  uwsgi_params;
				uwsgi_pass  127.0.0.1:9090;              #必须和uwsgi中的设置一致
				uwsgi_param UWSGI_SCRIPT webchat.wsgi;  #入口文件,即wsgi.py相对于项目根目录的位置,“.”相当于一层目录
				uwsgi_param UWSGI_CHDIR /var/www/webchat;       #项目根目录
				index  index.html index.htm;
				client_max_body_size 35m;
			}
	}

    # HTTPS server
    #
	server {
		listen       443 ssl;
		server_name  test.com;
		access_log logs/https-access.log;
		error_log logs/https-error.log;
		ssl on;
		#HTTPS服务端
		ssl_certificate      /home/web/myssl/server-cert.pem;
		ssl_certificate_key  /home/web/myssl/server-key.pem;
		#HTTPS双向验证,客户端密钥设置
		ssl_client_certificate /home/web/myssl/ca-cert.pem;
		ssl_verify_client on;

		ssl_session_cache    shared:SSL:1m;
		ssl_session_timeout  5m;

		ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
		ssl_ciphers AESGCM:ALL:!DH:!EXPORT:!RC4:+HIGH:!MEDIUM:!LOW:!aNULL:!eNULL;
		ssl_prefer_server_ciphers on;
		   
		error_page   500 502 503 504  /50x.html;
		location = /50x.html {
			 root   html;
		}
		location / {
			 proxy_set_header Host $host;
			 proxy_set_header X-Real-IP $remote_addr;
			 proxy_set_header REMOTE-HOST $remote_addr;
			 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
			 proxy_pass http://127.0.0.1:8888
		}
	}

}


注:uwsgi配置可以参考 nginx + uwsgi 部署python django web服务


你可能感兴趣的:(nginx,fastcgi,uwsgi)