部署web項目到nginx服務器
server{
server_name xxx.xxx.com;
listen 80;
location / {
proxy_set_header Connection "";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http:
proxy_redirect off;
}
}
server
{
listen 80;
server_name ceshi.banma.com; ------------》這里寫入你自己的域名(www.ceshi1.com)
index index.html index.htm index.php default.html default.htm default.php;
root /var/data/www/banma; --------項目的目錄
location / {
index index.html index.php;
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}
location ~ [^/]\.php(/|$)
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;
try_files $fastcgi_script_name =404;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /\.(ht|svn|bzr|git|hg|cvs) {
deny all;
}
}
listen 80;
server_name www.aaa.con aaa.con;
location / {
proxy_pass http:
}
location /proj1/ { proxy_pass http: } } server { listen 80; server_name www.bbb.con bbb.con; location / { proxy_pass http: } location /proj2/ { proxy_pass http: } } 這段配置的意思是訪問www.aaa.com或者aaa.com的請求,會被nginx映射到http: 這樣,我們就能夠在一台機器上發布針對若干個域名的WEB服務了。 server { listen 8000; server_name localhost; location / { root /var/www; } location = /project1 { root /var/www/project1; try_files $uri $uri/ /project1/index.html; index index.html index.htm; } location = /project2{ root /var/www/project2; try_files $uri $uri/ /project2/index.html; index index.html index.htm; } }
https配置
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name abc.com;
root /usr/share/nginx/html;
ssl_certificate "/root/keys/abc.com.pem";
ssl_certificate_key "/root/keys/abc.com.private.pem";
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 {
}
}
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name def.com;
root /usr/share/nginx/html;
ssl_certificate "/root/keys/def.com.pem";
ssl_certificate_key "/root/keys/def.com.private.pem";
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 {
}
}
server {
listen 80;
server_name x;
rewrite ^(.*)$ https://$host$1 permanent;
}
server {
listen 443;
server_name x;
ssl on;
ssl_certificate /etc/nginx/server.cer;
ssl_certificate_key /etc/nginx/server.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
client_max_body_size 16m;
client_body_buffer_size 128k;
proxy_pass http://online/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_next_upstream off;
proxy_connect_timeout 30;
proxy_read_timeout 300;
proxy_send_timeout 300;
}
}
環境變量的配置
修改 /etc/profile 文件,在文件末尾加上如下兩行代碼
PATH=$PATH:/usr/local/MATLAB/R2013a/bin
export PATH
export PATH=$PATH:/usr/local/nginx/sbin
最后執行命令 source /etc/profile 或執行點命令 ./profile 使其修改生效。