Cloud server JAVA operating environment construction (6) - install Nginx and related configuration
1. Install nginx via yum
yum -y install nginx
2. Configure nginx to start at boot
chkconfig nginx on
Then, call the following command to check whether the configuration is successful
chkconfig --list | grep nginx
The following results appear to indicate that the configuration is successful
3. Start nginx
service nginx start
PS If the startup fails at this time, it prompts Starting nginx: nginx: [emerg] socket() [::]:80 failed (97: Address family not supported by protocol), you need to modify the nginx configuration
vim /etc/nginx/conf.d/default.conf // find the following listen 80 default_server; // This line needs to be reserved, if not in the configuration, add it # listen [::]:80 default_server; // comment out this line
Other related commands
service nginx start // Start the nginx service service nginx stop // stop nginx service service nginx restart // restart nginx service
4. Access the webpage through http://public IP
If the nginx welcome page appears, then congratulations, the configuration is successful
5. Proxy access requests to tomcat
(1) Edit the nginx configuration file
vim /etc/nginx/conf.d/default.conf
(2) Modify the configuration file. Change the configuration file to the following
server { listen 80; server_name www.example.com; // Configure as your own domain name location / { // proxy all requests to tomcat proxy_pass http://localhost:8080; index index.html index.jsp index.htm; } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } }
6. Access the webpage through http://domain name
If the welcome page of Tomcat appears instead of the welcome page of nginx, then congratulations, you have successfully configured
related articles
1. Cloud server environment construction (1) - use putty or SecureCRT to connect to the server
2. Cloud server environment construction (2) - Replace the yum source in the server
3. Cloud server environment construction (3) - Install JDK
4. Cloud server environment construction (4) - install MySQL and related configuration
5. Cloud server environment construction (5) - install Tomcat and related configuration
6. Cloud server environment construction (6) - install Nginx and related configuration