nginx在ubuntu上的安装
优质
小牛编辑
131浏览
2023-12-01
1、安装Nginx
apt-get install nginx
装完应该能正常运行了。如果之前有装APACHE要改下端口。。。或者直接
apt-get remove apache2
/etc/init.d/nginx stop
/etc/init.d/nginx start
2、安装php-cgi
apt-get install php-cgi
3、改php-cgi的配置
Ubuntu下是 /etc/php5/cgi/php.ini
之前有安装过php的话会复制apache的配置文件 打开cgi.fix_pathinfo选项: cgi.fix_pathinfo=1;
4、改Nginx的fastcgi传递参数
Ubuntu下是/etc/nginx/fastcgi_params
默认应该已经设置好了,内容差不多就下面那样:fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length;fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param REQUEST_URI $request_uri; fastcgi_param DOCUMENT_URI $document_uri; fastcgi_param DOCUMENT_ROOT $document_root; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_PORT $remote_port; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name; # PHP only, required if PHP was built with –enable-force-cgi-redirect fastcgi_param REDIRECT_STATUS 200;
5、创建VHost配置(这里只说Ubuntu下的,也就路径和包含文件目录的区别了)
在/etc/nginx/sites-available/
下创建服务器配置文件比如myserver ln -n /etc/nginx/sites-available/myserver /etc/nginx/sites-enabled/myserver
其实懒的话直接创建在enabled里也没问题 内容填: 代码: server {
listen 80;
server_name myserver.com;
access_log /var/log/nginx/myserver.access.log;location / {
root /wwwroot/myserver;
index index.php;
autoindex off;
}
location ~ .php$ {
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME /wwwroot/myserver/$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
}
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/nginx-default;
}
# deny access to .htaccess files, if Apache’s document root
location ~ /.ht {
deny all;
}
}
6、安装spawn-fcgi
下载可到这里,这东西已经独立出来了http://redmine.lighttpd.net/projects/spawn-fcgi/wiki
下完后解压编译sudo ./configure –prefix=/usr/local sudo make sudo make install
7、启动spaw-fcgi
sudo spawn-fcgi -a 127.0.0.1 -p 9000 -u www-data -g www-data -f /usr/bin/php5-cgi -F 10
对后面10进程不爽的人可以取消或是加到1008、重启Nginx
/etc/init.d/nginx restart
9、定义下hosts就可以看结果啦
编辑/etc/hosts
加入 127.0.0.1 myserver.com
然后打开浏览器就可以看结果啦~ 有问题欢迎指出~~