nginx多端口配置

如何配置nginx的端口来访问不同网站

Posted by MaxBear 4 years ago

nginx多端口配置

如何配置nginx的端口来访问不同网站

可以.在配置nginx.conf里的http下配置两个server即可:

server { 
    listen 81; 
    root   /path/to/site1; 
    index index.html index.htm index.php; 
    location ~ \.php$ { 
        try_files $uri =404; 
        include fastcgi_params; 
        fastcgi_pass 127.0.0.1:9000; 
        fastcgi_index index.php; 
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    } 
} 
server { 
    listen 82; 
    root   /path/to/site2; 
    index index.html index.htm index.php; 
    location ~ \.php$ { 
        try_files $uri =404; 
        include fastcgi_params; 
        fastcgi_pass 127.0.0.1:9000; 
        fastcgi_index index.php; 
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    } 
}