win2003 nginx 0.8.38 installation configuration memo

  • 2020-05-06 12:13:39
  • OfStack

nginx is said to be the up-and-coming Web server of the last few years, the "Apache killer", written by Russian programmers. Web is a lightweight Web server that is also said to take up fewer resources, be highly concurrent, and in some cases be 10 times more efficient than Apache. Many large portal stations are in use at home and abroad.

Unable to resist the temptation, I decided to try Windows Server 2003 installation and integration with PHP.

By the end of May 2010, the latest version is 0.8.38 nginx, can go to the http: / / www nginx. org/download.

Unzip PHP to C:\ php-5.3.2-Win32-VC6-x86 \, correctly configure php.ini file.

Directly unzip the downloaded nginx-0.8.38.zip file to C:\ nginx-0.8.38 \, folder structure:

conf\
contrib\
docs\
html\
logs\
temp\
nginx.exe

Double-click to run the nginx.exe file, and nginx begins to provide the service.
The html\ folder is the site's default root directory.
conf\ place nginx configuration related files. The configuration file nginx.conf reads as follows (the statement that starts with the # has been commented out for reference) :

server {... } section confers nginx http service port (default is 80), domain name, character set, root folder, home page file and so on.

The following sections are configured to integrate nginx and PHP in fastcgi mode. "C:/ nginx-0.8.38 /html" indicates the root folder of the website:
 
location ~ \.php$ { 
# root html; 
fastcgi_pass 127.0.0.1:9000; 
fastcgi_index index.php; 
fastcgi_param SCRIPT_FILENAME C:/nginx-0.8.38/html$fastcgi_script_name; 
include fastcgi_params; 
} 

#user nobody; 
worker_processes 1; 

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

#pid logs/nginx.pid; 

events { 
worker_connections 1024; 
} 

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 65; 

#gzip on; 

server { 
listen 80; 
server_name localhost; 

#charset koi8-r; 

#access_log logs/host.access.log main; 

location / { 
root html; 
index index.html index.htm; 
autoindex on; 
} 

#error_page 404 /404.html; 

# redirect server error pages to the static page /50x.html 
# 
error_page 500 502 503 504 /50x.html; 
location = /50x.html { 
root html; 
} 

# proxy the PHP scripts to Apache listening on 127.0.0.1:80 
# 
#location ~ \.php$ { 
# proxy_pass http://127.0.0.1; 
#} 

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 
# 
location ~ \.php$ { 
# root html; 
fastcgi_pass 127.0.0.1:9000; 
fastcgi_index index.php; 
fastcgi_param SCRIPT_FILENAME C:/nginx-0.8.38/html$fastcgi_script_name; 
include fastcgi_params; 
} 

# deny access to .htaccess files, if Apache's document root 
# concurs with nginx's one 
# 
#location ~ /\.ht { 
# deny all; 
#} 
} 

# another virtual host using mix of IP-, name-, and port-based configuration 
# 
#server { 
# listen 8000; 
# listen somename:8080; 
# server_name somename alias another.alias; 

# location / { 
# root html; 
# index index.html index.htm; 
# } 
#} 

# HTTPS server 
# 
#server { 
# listen 443; 
# server_name localhost; 

# ssl on; 
# ssl_certificate cert.pem; 
# ssl_certificate_key cert.key; 

# ssl_session_timeout 5m; 

# ssl_protocols SSLv2 SSLv3 TLSv1; 
# ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP; 
# ssl_prefer_server_ciphers on; 

# location / { 
# root html; 
# index index.html index.htm; 
# } 
#} 
} 

At this point, open the browser on the local machine, browse http://localhost, you can see the message "Welcome to nginx!" , from the index.html file under html.

In order to really work with PHP, you must also run php-cgi.exe for PHP. To do this, in the command window, switch to the php-cgl.exe folder, C:\ PHP-5.3.2-Win32-VC6-x86, php-cgi.exe-b 127.0.0.1:9000,

C:\ php-5.3.2-Win32-VC6-x86 > php-cgi. Es124en-b 127.0.0.1:9000

Here 127.0.0.1:9000 is the one we configured in the nginx.conf file, and the port number must be the same.

The order in which the nginx.exe and php-cgi.exe commands are run has no effect on the parsing of PHP files.

At this time, we in the root directory to devolve a xxx php file in your browser's address bar enter http: / / localhost xxx php, should see the results. Suggested file contents:

< ?php
phpinfo();
? >

We can see a lot of useful information about the PHP environment.

nginx can also be configured to implement reverse proxy, multiple virtual hosts, url redirection, and more.

Related articles: